Part Number Hot Search : 
MM1510 DD306 15C30 MC33460 TA7739P MN101 74HC40 F1040
Product Description
Full Text Search
 

To Download AT90S231302 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  1 features ? utilizes the avr ? risc architecture  avr ? high-performance and low-power risc architecture ? 118 powerful instructions ? most single clock cycle execution ? 32x8generalpurposeworkingregisters ? up to 10 mips throughput at 10 mhz  data and non-volatile program memory ? 2k bytes of in-system programmable flash endurance 1,000 write/erase cycles ? 128 bytes of sram ? 128 bytes of in-system programmable eeprom endurance: 100,000 write/erase cycles ? programming lock for flash program and eeprom data security  peripheral features ? one 8-bit timer/counter with separate prescaler ? one 16-bit timer/counter with separate prescaler, compare, capture modes and 8-, 9-, or 10-bit pwm ? on-chip analog comparator ? programmable watchdog timer with on-chip oscillator ? spi serial interface for in-system programming ?fullduplexuart   special microcontroller features ? low-power idle and power-down modes ? external and internal interrupt sources   specifications ? low-power, high-speed cmos process technology ? fully static operation  power consumption at 4 mhz, 3v, 25c ? active: 2.8 ma ? idle mode: 0.8 ma ? power-down mode: <1 a  i/o and packages ? 15 programmable i/o lines ? 20-pin pdip and soic  operating voltages ? 2.7 - 6.0v (at90s2313-4) ? 4.0 - 6.0v (at90s2313-10)  speed grades ? 0 - 4 mhz (at90s2313-4) ? 0 - 10 mhz (at90s2313-10) pin configuration pdip/soic 8-bit microcontroller with 2k bytes of in-system programmable flash at90s2313 rev. 0839i?avr?06/02
2 at90s2313 0839i?avr?06/02 description the at90s2313 is a low-power cmos 8-bit microcontroller based on the avr risc architecture. by executing powerful instructions in a single clock cycle, the at90s2313 achieves throughputs approaching 1 mips per mhz allowing the system designer to optimize power consumption versus processing speed. the avr core combines a rich instruction set with 32 general purpose working registers. all the 32 registers are directly connected to the arithmetic logic unit (alu), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. the resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional cisc microcontrollers. figure 1. the at90s2313 block diagram the at90s2313 provides the following features: 2k bytes of in-system programmable flash, 128 bytes eeprom, 128 bytes sram, 15 general purpose i/o lines, 32 general purpose working registers, flexible timer/counters with compare modes, internal and external interrupts, a programmable serial uart, programmable watchdog timer with internal oscillator, an spi serial port for flash memory downloading and two software
3 at90s2313 0839i?avr?06/02 selectable power-saving modes. the idle mode stops the cpu while allowing the sram, timer/counters, spi port and interrupt system to continue functioning. the power-down mode saves the register contents but freezes the oscillator, disabling all other chip functions until the next external interrupt or hardware reset. the device is manufactured using atmel?s high-density non-volatile memory technology. the on-chip in-system programmable flash allows the program memory to be repro- grammed in-system through an spi serial interface or by a conventional non-volatile memory programmer. by combining an enhanced risc 8-bit cpu with in-system pro- grammable flash on a monolithic chip, the atmel at90s2313 is a powerful microcontroller that provides a highly flexible and cost-effective solution to many embed- ded control applications. the at90s2313 avr is supported with a full suite of program and system development tools including: c compilers, macro assemblers, program debugger/simulators, in-cir- cuit emulators and evaluation kits. pin descriptions vcc supply voltage pin. gnd ground pin. port b (pb7..pb0) port b is an 8-bit bi-directional i/o port. port pins can provide internal pull-up resistors (selected for each bit). pb0 and pb1 also serve as the positive input (ain0) and the negative input (ain1), respectively, of the on-chip analog comparator. the port b out- put buffers can sink 20 ma and can drive led displays directly. when pins pb0 to pb7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. the port b pins are tri-stated when a reset condition becomes active, even if the clock is not active. port b also serves the functions of various special features of the at90s2313 as listed on page 51. port d (pd6..pd0) port d has seven bi-directional i/o ports with internal pull-up resistors, pd6..pd0. the port d output buffers can sink 20 ma. as inputs, port d pins that are externally pulled low will source current if the pull-up resistors are activated. the port d pins are tri-stated when a reset condition becomes active, even if the clock is not active. port d also serves the functions of various special features of the at90s2313 as listed on page 56. reset reset input. a low level on this pin for more than 50 ns will generate a reset, even if the clock is not running. shorter pulses are not guaranteed to generate a reset. xtal1 input to the inverting oscillator amplifier and input to the internal clock operating circuit. xtal2 output from the inverting oscillator amplifier.
4 at90s2313 0839i?avr?06/02 crystal oscillator xtal1 and xtal2 are input and output, respectively, of an inverting amplifier that can be configured for use as an on-chip oscillator, as shown in figure 2. either a quartz crystal or a ceramic resonator may be used. to drive the device from an external clock source, xtal2 should be left unconnected while xtal1 is driven, as shown in figure 3. figure 2. oscillator connections note: when using the mcu oscillator as a clock for an external device, an hc buffer should be connected as indicated in the figure. figure 3. external clock drive configuration xtal2 xtal1 gnd c2 c1 max 1 hc buffer hc
5 at90s2313 0839i ? avr ? 06/02 architectural overview the fast-access register file concept contains 32 x 8-bit general purpose working reg- isters with a single clock cycle access time. this means that during one single clock cycle, one alu (arithmetic logic unit) operation is executed. two operands are output from the register file, the operation is executed, and the result is stored back in the register file ? in one clock cycle. figure 4. the at90s2313 avr risc architecture six of the 32 registers can be used as three 16-bit indirect address register pointers for data space addressing ? enabling efficient address calculations. one of the three address pointers is also used as the address pointer for the constant table look-up func- tion. these added function registers are the 16-bit x-register, y-register, and z-register. the alu supports arithmetic and logic functions between registers or between a con- stant and a register. single register operations are also executed in the alu. figure 4 shows the at90s2313 avr risc microcontroller architecture. in addition to the register operation, the conventional memory addressing modes can be used on the register file as well. this is enabled by the fact that the register file is assigned the 32 lowermost data space addresses ($00 - $1f), allowing them to be accessed as though they were ordinary memory locations.
6 at90s2313 0839i ? avr ? 06/02 the i/o memory space contains 64 addresses for cpu peripheral functions such as control registers, timer/counters, a/d converters and other i/o functions. the i/o mem- ory can be accessed directly or as the data space locations following those of the register file, $20 - $5f. the avr has harvard architecture ? with separate memories and buses for program and data. the program memory is accessed with a 2-stage pipeline. while one instruc- tion is being executed, the next instruction is pre-fetched from the program memory. this concept enables instructions to be executed in every clock cycle. the program memory is in-system programmable flash memory. with the relative jump and call instructions, the whole 1k address space is directly accessed. most avr instructions have a single 16-bit word format. every program memory address contains a 16- or 32-bit instruction. during interrupts and subroutine calls, the return address program counter (pc) is stored on the stack. the stack is effectively allocated in the general data sram, and consequently the stack size is only limited by the total sram size and the usage of the sram. all user programs must initialize the sp in the reset routine (before subroutines or interrupts are executed). the 8-bit stack pointer (sp) is read/write accessible in the i/o space. the 128 bytes data sram + register file and i/o registers can be easily accessed through the five different addressing modes supported in the avr architecture. the memory spaces in the avr architecture are all linear and regular memory maps. figure 5. memory maps a flexible interrupt module has its control registers in the i/o space with an additional global interrupt enable bit in the status register. all the different interrupts have a sep- arate interrupt vector in the interrupt vector table at the beginning of the program memory. the different interrupts have priority in accordance with their interrupt vector position. the lower the interrupt vector address, the higher the priority.
7 at90s2313 0839i ? avr ? 06/02 general purpose register file figure 6 shows the structure of the 32 general purpose registers in the cpu. figure 6. avr cpu general purpose working registers all the register operating instructions in the instruction set have direct and single-cycle access to all registers. the only exception is the five constant arithmetic and logic instructions sbci, subi, cpi, andi, ori between a constant and a register and the ldi instruction for load immediate constant data. these instructions apply to the second half of the registers in the register file (r16..r31). the general sbc, sub, cp, and, or, and all other operations between two registers or on a single register apply to the entire register file. as shown in figure 6, each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user data space. although the register file is not physically implemented as sram locations, this memory organization pro- vides great flexibility in access of the registers, as the x-, y-, and z-registers can be set to index any register in the file. x-register, y-register, and z- register the registers r26..r31 have some added functions to their general purpose usage. these registers are the address pointers for indirect addressing of the data space. the three indirect address registers x, y and z are defined in figure 7. figure 7. x-, y-, and z-registers 70addr. r0 $00 r1 $01 r2 $02 ? r13 $0d general r14 $0e purpose r15 $0f working r16 $10 registers r17 $11 ? r26 $1a x-register low byte r27 $1b x-register high byte r28 $1c y-register low byte r29 $1d y-register high byte r30 $1e z-register low byte r31 $1f z-register high byte 15 0 x-register 7 0 7 0 r27 ($1b) r26 ($1a) 15 0 y-register 7 0 7 0 r29 ($1d) r28 ($1c) 15 0 z-register 7 0 7 0 r31 ($1f) r30 ($1e)
8 at90s2313 0839i ? avr ? 06/02 in the different addressing modes these address registers have functions as fixed dis- placement, automatic increment and decrement (see the descriptions for the different instructions). alu ? arithmetic logic unit the high-performance avr alu operates in direct connection with all the 32 general purpose working registers. within a single clock cycle, alu operations between regis- ters in the register file are executed. the alu operations are divided into three main categories ? arithmetic, logical, and bit functions. in-system programmable flash program memory the at90s2313 contains 2k bytes on-chip in-system programmable flash memory for program storage. since all instructions are 16- or 32-bit words, the flash is organized as 1k x 16. the flash memory has an endurance of at least 1,000 write/erase cycles. the at90s2313 program counter (pc) is 10 bits wide, thus addressing the 1,024 pro- gram memory addresses. see page 60 for a detailed description on flash data downloading. see page 10 for the different addressing modes. eeprom data memory the at90s2313 contains 128 bytes of eeprom data memory. it is organized as a sep- arate data space in which single bytes can be read and written. the eeprom has an endurance of at least 100,000 write/erase cycles. the access between the eeprom and the cpu is described on page 39, specifying the eeprom address register, the eeprom data register and the eeprom control register. for the spi data downloading, see page 68 for a detailed description.
9 at90s2313 0839i ? avr ? 06/02 sram data memory figure 8 shows how the at90s2313 data memory is organized. figure 8. sram organization the 224 data memory locations address the register file, i/o memory and the data sram. the first 96 locations address the register file + i/o memory, and the next 128 locations address the data sram. the five different addressing modes for the data memory cover: direct, indirect with dis- placement, indirect, indirect with pre-decrement and indirect with post-increment. in the register file, registers r26 to r31 feature the indirect addressing pointer registers. the direct addressing reaches the entire data address space. the indirect with displacement mode features 63 address locations reached from the base address given by the y- and z-registers. when using register indirect addressing modes with automatic pre-decrement and post- increment, the address registers x, y, and z are used and decremented and incremented. the 32 general purpose working registers, 64 i/o registers and the 128 bytes of data sram in the at90s2313 are all directly accessible through all these addressing modes. register file data address space r0 $00 r1 $01 r2 $02 ?? r29 $1d r30 $1e r31 $1f i/o registers $00 $20 $01 $21 $02 $22 ?? $3d $5d $3e $5e $3f $5f internal sram $60 $61 $62 ? $dd $de $df
10 at90s2313 0839i ? avr ? 06/02 program and data addressing modes the at90s2313 avr risc microcontroller supports powerful and efficient addressing modes for access to the program memory (flash) and data memory. this section describes the different addressing modes supported by the avr architecture. in the fig- ures, op means the operation code part of the instruction word. to simplify, not all figures show the exact location of the addressing bits. register direct, single register rd figure 9. direct single register addressing the operand is contained in register d (rd). register direct, two registers rd and rr figure 10. direct register addressing, two registers operands are contained in register r (rr) and d (rd). the result is stored in register d (rd). i/o direct figure 11. i/o direct addressing
11 at90s2313 0839i ? avr ? 06/02 operand address is contained in 6 bits of the instruction word. n is the destination or source register address. data direct figure 12. direct data addressing a 16-bit data address is contained in the 16 lsbs of a 2-word instruction. rd/rr specify the destination or source register. data indirect with displacement figure 13. data indirect with displacement operand address is the result of the y- or z-register contents added to the address con- tained in 6 bits of the instruction word. data indirect figure 14. data indirect addressing operand address is the contents of the x-, y-, or z-register.
12 at90s2313 0839i ? avr ? 06/02 data indirect with pre- decrement figure 15. data indirect addressing with pre-decrement the x-, y-, or z-register is decremented before the operation. operand address is the decremented contents of the x-, y-, or z-register. data indirect with post- increment figure 16. data indirect addressing with post-increment the x-, y-, or z-register is incremented after the operation. operand address is the con- tents of the x-, y-, or z-register prior to incrementing. constant addressing using the lpm instruction figure 17. code memory constant addressing constant byte address is specified by the z-register contents. the 15 msbs select word address (0 - 1k), the lsb selects low byte if cleared (lsb = 0) or high byte if set (lsb = 1).
13 at90s2313 0839i ? avr ? 06/02 indirect program addressing, ijmp and icall figure 18. indirect program memory addressing program execution continues at address contained by the z-register (i.e., the pc is loaded with the contents of the z-register). relative program addressing, rjmp and rcall figure 19. relative program memory addressing program execution continues at address pc + k + 1. the relative address k is -2048 to 2047.
14 at90s2313 0839i ? avr ? 06/02 memory access and instruction execution timing this section describes the general access timing concepts for instruction execution and internal memory access. theavrcpuisdrivenbythesystemclock ? , directly generated from the external clock crystal for the chip. no internal clock division is used. figure 20 shows the parallel instruction fetches and instruction executions enabled by the harvard architecture and the fast-access register file concept. this is the basic pipelining concept to obtain up to 1 mips per mhz with the corresponding unique results for functions per cost, functions per clocks and functions per power-unit. figure 20. the parallel instruction fetches and instruction executions figure 21 shows the internal timing concept for the register file. in a single clock cycle an alu operation using two register operands is executed, and the result is stored back to the destination register. figure 21. single-cycle alu operation the internal data sram access is performed in two system clock cycles as described in figure 22. system clock ? 1st instruction fetch 1st instruction execute 2nd instruction fetch 2nd instruction execute 3rd instruction fetch 3rd instruction execute 4th instruction fetch t1 t2 t3 t4 system clock ? total execution time register operands fetch alu operation execute result write back t1 t2 t3 t4
15 at90s2313 0839i ? avr ? 06/02 figure 22. on-chip data sram access cycles i/o memory the i/o space definition of the at90s2313 is shown in table 1. system clock ? wr rd data data address address t1 t2 t3 t4 prev. address read write ta ble 1. at90s2313 i/o space (1) address hex name function $3f ($5f) sreg status register $3d ($5d) spl stack pointer low $3b ($5b) gimsk general interrupt mask register $3a ($5a) gifr general interrupt flag register $39 ($59) timsk timer/counter interrupt mask register $38 ($58) tifr timer/counter interrupt flag register $35 ($55) mcucr mcu general control register $33 ($53) tccr0 timer/counter 0 control register $32 ($52) tcnt0 timer/counter 0 (8-bit) $2f ($4f) tccr1a timer/counter 1 control register a $2e ($4e) tccr1b timer/counter 1 control register b $2d ($4d) tcnt1h timer/counter 1 high byte $2c ($4c) tcnt1l timer/counter 1 low byte $2b ($4b) ocr1ah output compare register 1 high byte $2a ($4a) ocr1al output compare register 1 low byte $25 ($45) icr1h t/c 1 input capture register high byte $24 ($44) icr1l t/c 1 input capture register low byte $21 ($41) wdtcr watchdog timer control register $1e ($3e) eear eeprom address register $1d ($3d) eedr eeprom data register $1c ($3c) eecr eeprom control register $18 ($38) portb data register, port b $17 ($37) ddrb data direction register, port b $16 ($36) pinb input pins, port b
16 at90s2313 0839i ? avr ? 06/02 note: 1. reserved and unused locations are not shown in the table. all at90s2313 i/o and peripherals are placed in the i/o space. the i/o locations are accessed by the in and out instructions transferring data between the 32 general pur- pose working registers and the i/o space. i/o registers within the address range $00 - $1f are directly bit-accessible using the sbi and cbi instructions. in these registers, the value of single bits can be checked by using the sbis and sbic instructions. refer to the instruction set section for more details. when using the i/o specific commands in and out, the i/o addresses $00 - $3f must be used. when addressing i/o registers as sram, $20 must be added to this address. all i/o register addresses throughout this document are shown with the sram address in parentheses. for compatibility with future devices, reserved bits should be written to zero if accessed. reserved i/o memory addresses should never be written. some of the status flags are cleared by writing a logical ? 1 ? to them. note that the cbi and sbi instructions will operate on all bits in the i/o register, writing a ? 1 ? back into any flag read as set, thus clearing the flag. the cbi and sbi instructions work with registers $00 to $1f only. the i/o and peripherals control registers are explained in the following sections. status register ? sreg the avr status register (sreg) at i/o space location $3f ($5f) is defined as:  bit 7 ? i: global interrupt enable the global interrupt enable bit must be set (one) for the interrupts to be enabled. the individual interrupt enable control is then performed in separate control registers. if the global interrupt enable bit is cleared (zero), none of the interrupts are enabled indepen- dent of the individual interrupt enable settings. the i-bit is cleared by hardware after an interrupt has occurred, and is set by the reti instruction to enable subsequent interrupts. bit6?t:bitcopystorage the bit copy instructions bld (bit load) and bst (bit store) use the t-bit as source and destination for the operated bit. a bit from a register in the register file can be cop- ied into t by the bst instruction, and a bit in t can be copied into a bit in a register in the register file by the bld instruction. $12 ($32) portd data register, port d $11 ($31) ddrd data direction register, port d $10 ($30) pind input pins, port d $0c ($2c) udr uart i/o data register $0b ($2b) usr uart status register $0a ($2a) ucr uart control register $09 ($29) ubrr uart baud rate register $08 ($28) acsr analog comparator control and status register ta ble 1. at90s2313 i/o space (1) (continued) address hex name function bit 76543210 $3f ($5f) i thsvnzcsreg read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000
17 at90s2313 0839i ? avr ? 06/02  bit 5 ? h: half-carry flag the half-carry flag h indicates a half-carry in some arithmetic operations. see the instruction set description for detailed information.  bit 4 ? s: sign bit, s = n v the s-bit is always an exclusive or between the negative flag n and the two ? s comple- ment overflow flag v. see the instruction set description for detailed information.  bit 3 ? v: two?s complement overflow flag the two ? s complement overflow flag v supports two ? s complement arithmetics. see the instruction set description for detailed information.  bit 2 ? n: negative flag the negative flag n indicates a negative result after the different arithmetic and logic operations. see the instruction set description for detailed information.  bit 1 ? z: zero flag the zero flag z indicates a zero result after the different arithmetic and logic opera- tions. see the instruction set description for detailed information.  bit 0 ? c: carry flag the carry flag c indicates a carry in an arithmetic or logic operation. see the instruc- tion set description for detailed information. note that the status register is not automatically stored when entering an interrupt rou- tine and restored when returning from an interrupt routine. this must be handled by software. stack pointer ? sp an 8-bit register at i/o address $3d ($5d) forms the stack pointer of the at90s2313. 8 bits are used to address the 128 bytes of sram in locations $60 - $df. the stack pointer points to the data sram stack area where the subroutine and inter- rupt stacks are located. this stack space in the data sram must be defined by the program before any subroutine calls are executed or interrupts are enabled. the stack pointer must be set to point above $60. the stack pointer is decremented by 1 when data is pushed onto the stack with the push instruction, and it is decremented by 2 when an address is pushed onto the stack with subroutine calls and interrupts. the stack pointer is incremented by 1 when data is popped from the stack with the pop instruction, and it is incremented by 2 when an address is popped from the stack with return from subroutine ret or return from interrupt reti. bit 76543210 $3d ($5d) sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 spl read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000
18 at90s2313 0839i ? avr ? 06/02 reset and interrupt handling the at90s2313 provides 10 different interrupt sources. these interrupts and the sepa- rate reset vector each have a separate program vector in the program memory space. all the interrupts are assigned individual enable bits that must be set (one) together with the i-bit in the status register in order to enable the interrupt. the lowest addresses in the program memory space are automatically defined as the reset and interrupt vectors. the complete list of vectors is shown in table 2. the list also determines the priority levels of the different interrupts. the lower the address, the higher the priority level. reset has the highest priority, and next is int0 (the external interrupt request 0), etc. the most typical and general program setup for the reset and interrupt vector addresses are: address labels code comments $000 rjmp reset ; reset handler $001 rjmp ext_int0 ; irq0 handler $002 rjmp ext_int1 ; irq1 handler $003 rjmp tim_capt1 ; timer1 capture handler $004 rjmp tim_comp1 ; timer1 compare handler $005 rjmp tim_ovf1 ; timer1 overflow handler $006 rjmp tim_ovf0 ; timer0 overflow handler $007 rjmp uart_rxc ; uart rx complete handler $008 rjmp uart_dre ; udr empty handler $009 rjmp uart_txc ; uart tx complete handler $00a rjmp ana_comp ; analog comparator handler ; $00b main: ldi r16,low(ramend); main program start $00c out spl,r16 $00d xxx ???? ta ble 2. reset and interrupt vectors vector no. program address source interrupt definition 1 $000 reset hardware pin, power-on reset and watchdog reset 2 $001 int0 external interrupt request 0 3 $002 int1 external interrupt request 1 4 $003 timer1 capt1 timer/counter1 capture event 5 $004 timer1 comp1 timer/counter1 compare match 6 $005 timer1 ovf1 timer/counter1 overflow 7 $006 timer0 ovf0 timer/counter0 overflow 8 $007 uart, rx uart, rx complete 9 $008 uart, udre uart data register empty 10 $009 uart, tx uart, tx complete 11 $00a ana_comp analog comparator
19 at90s2313 0839i ? avr ? 06/02 reset sources the at90s2313 has three sources of reset:  power-on reset. the mcu is reset when the supply voltage is below the power-on reset threshold (v pot ).  external reset. the mcu is reset when a low level is present on the reset pin for more than 50 ns.  watchdog reset. the mcu is reset when the watchdog timer period expires and the watchdog is enabled. during reset, all i/o registers are then set to their initial values, and the program starts execution from address $000. the instruction placed in address $000 must be an rjmp (relative jump) instruction to the reset handling routine. if the program never enables an interrupt source, the interrupt vectors are not used, and regular program code can be placed at these locations. the circuit diagram in figure 23 shows the reset logic. table 3 defines the timing and electrical parameters of the reset circuitry. figure 23. reset logic note: 1. the power-on reset will not work unless the supply voltage has been below v pot (falling). the user can select the start-up time according to typical oscillator start-up. the num- ber of wdt oscillator cycles used for each time-out is shown in table 4. the frequency of the watchdog oscillator is voltage-dependent, as shown in ? typical characteristics ? on page 74. ta ble 3. reset characteristics (v cc =5.0v) symbol parameter min typ max units v pot (1) power-on reset threshold voltage (rising) 1.0 1.4 1.8 v power-on reset threshold voltage (falling) 0.4 0.6 0.8 v v rst reset pin threshold voltage ? 0.85 v cc v t tout reset delay time-out period fstrt unprogrammed 11.0 16.0 21.0 ms t tout reset delay time-out period fstrt programmed 0.25 0.28 0.31 ms
20 at90s2313 0839i ? avr ? 06/02 power-on reset a power-on reset (por) circuit ensures that the device is reset from power-on. as shown in figure 23, an internal timer is clocked from the watchdog timer. this timer prevents the mcu from starting until after a certain period after v cc has reached the power-on threshold voltage (v pot )(seefigure24).thefstrtfusebitintheflash can be programmed to give a shorter start-up time if a ceramic resonator or any other fast-start oscillator is used to clock the mcu. if the built-in start-up delay is sufficient, reset can be connected to v cc directly or via an external pull-up resistor. by holding the reset pin low for a period after v cc has been applied, the power-on reset period can be extended. refer to figure 25 for a tim- ing example of this. figure 24. mcu start-up, reset tied to v cc . figure 25. mcu start-up, reset controlled externally ta ble 4. number of watchdog oscillator cycles fstrt time-out at v cc = 5v number of wdt cycles programmed 0.28 ms 256 unprogrammed 16.0 ms 16k vcc reset time-out internal reset t tout v pot v rst vcc reset time-out internal reset t tout v pot v rst
21 at90s2313 0839i ? avr ? 06/02 external reset an external reset is generated by a low level on the reset pin. reset pulses longer than 50 ns will generate a reset, even if the clock is not running. shorter pulses are not guaranteed to generate a reset. when the applied signal reaches the reset threshold voltage (v rst ) on its positive edge, the delay timer starts the mcu after the time-out period t tout has expired. figure 26. external reset during operation watchdog reset when the watchdog times out, it will generate a short reset pulse of one xtal cycle duration. on the falling edge of this pulse, the delay timer starts counting the time-out period t tout . refer to page 37 for details on operation of the watchdog. figure 27. watchdog reset during operation interrupt handling the at90s2313 has two 8-bit interrupt mask control registers: the gimsk (general interrupt mask register) and the timsk (timer/counter interrupt mask register). when an interrupt occurs, the global interrupt enable i-bit is cleared (zero) and all inter- rupts are disabled. the user software can set (one) the i-bit to enable interrupts. the i- bit is set (one) when a return from interrupt instruction (reti) is executed. for interrupts triggered by events that can remain static (e.g., the output compare register1 matching the value of timer/counter1), the interrupt flag is set when the event occurs. if the interrupt flag is cleared and the interrupt condition persists, the flag will not be set until the event occurs the next time. when the program counter is vectored to the actual interrupt vector in order to execute the interrupt handling routine, hardware clears the corresponding flag that generated the
22 at90s2313 0839i ? avr ? 06/02 interrupt. some of the interrupt flags can also be cleared by writing a logical ? 1 ? to the flag bit position(s) to be cleared. if an interrupt condition occurs when the corresponding interrupt enable bit is cleared (zero), the interrupt flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. if one or more interrupt conditions occur when the global interrupt enable bit is cleared (zero), the corresponding interrupt flag(s) will be set and remembered until the global interrupt enable bit is set (one), and will be executed by order of priority. note that external level interrupt does not have a flag, and will only be remembered for as long as the interrupt condition is active. note that the status register is not automatically stored when entering an interrupt rou- tine and restored when returning from an interrupt routine. this must be handled by software. general interrupt mask register ? gimsk  bit 7 ? int1: external interrupt request 1 enable when the int1 bit is set (one) and the i-bit in the status register (sreg) is set (one), the external pin interrupt is enabled. the interrupt sense control1 bits 1/0 (isc11 and isc10) in the mcu general control register (mcucr) defines whether the external interrupt is activated on rising or falling edge of the int1 pin or level sensed. activity on the pin will cause an interrupt request even if int1 is configured as an output. the corre- sponding interrupt of external interrupt request 1 is executed from program memory address $002. see also ? external interrupts ? .  bit 6 ? int0: external interrupt request 0 enable when the int0 bit is set (one) and the i-bit in the status register (sreg) is set (one), the external pin interrupt is enabled. the interrupt sense control0 bits 1/0 (isc01 and isc00) in the mcu general control register (mcucr) defines whether the external interrupt is activated on rising or falling edge of the int0 pin or level sensed. activity on the pin will cause an interrupt request even if int0 is configured as an output. the corre- sponding interrupt of external interrupt request 0 is executed from program memory address $001. see also ? external interrupts. ?  bits 5..0 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read as zero. bit 7 6 5 4 3 2 1 0 $3b ($5b) int1 int0 ? ? ? ? ? ? gimsk read/write r/w r/w r r r r r r initial value 0 0 0 0 0 0 0 0
23 at90s2313 0839i ? avr ? 06/02 general interrupt flag register ? gifr  bit 7 ? intf1: external interrupt flag1 when an edge on the int1 pin triggers an interrupt request, the corresponding interrupt flag, intf1, becomes set (one). if the i-bit in sreg and the corresponding interrupt enable bit, int1 bit in gimsk, are set (one), the mcu will jump to the interrupt vector. the flag is cleared when the interrupt routine is executed. alternatively, the flag can be cleared by writing a logical ? 1 ? to it. the flag is always cleared when int1 is configured as level interrupt.  bit 6 ? intf0: external interrupt flag0 when an edge on the int0 pin triggers an interrupt request, the corresponding interrupt flag, intf0, becomes set (one). if the i-bit in sreg and the corresponding interrupt enable bit, int0 bit in gimsk, are set (one), the mcu will jump to the interrupt vector. the flag is cleared when the interrupt routine is executed. alternatively, the flag can be cleared by writing a logical ? 1 ? to it. the flag is always cleared when int0 is configured as level interrupt.  bits 5..0 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read as zero. note that external level interrupt does not have a flag, and will only be remembered for as long as the interrupt condition is active. timer/counter interrupt mask register ? timsk  bit 7 ? toie1: timer/counter1 overflow interrupt enable when the toie1 bit is set (one) and the i-bit in the status register is set (one), the timer/counter1 overflow interrupt is enabled. the corresponding interrupt (at vector $005) is executed if an overflow in timer/counter1 occurs (i.e., when the tov1 bit is set in the timer/counter interrupt flag register [tifr]).  bit 6 ? ocie1a: timer/counter1 output compare match interrupt enable when the ocie1a bit is set (one) and the i-bit in the status register is set (one), the timer/counter1 compare match interrupt is enabled. the corresponding interrupt (at vector $004) is executed if a compare match in timer/counter1 occurs (i.e., when the ocf1a bit is set in the timer/counter interrupt flag register [tifr]).  bit 5,4 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read as zero. bit 7 6 5 4 3 2 1 0 $3a ($5a) intf1 intf0 ? ? ? ? ? ? gifr read/write r/w r/w r r r r r r initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 $39 ($59) toie1 ocie1a ? ? ticie1 ? toie0 ? timsk read/write r/w r/w r r r/w r r/w r initial value 0 0 0 0 0 0 0 0
24 at90s2313 0839i ? avr ? 06/02  bit 3 ? ticie1: timer/counter1 input capture interrupt enable when the ticie1 bit is set (one) and the i-bit in the status register is set (one), the timer/counter1 input capture event interrupt is enabled. the corresponding interrupt (at vector $003) is executed if a capture-triggering event occurs on pd6(icp) (i.e., when the icf1 bit is set in the timer/counter interrupt flag register [tifr]).  bit 2 ? res: reserved bit this bit is a reserved bit in the at90s2313 and always reads as zero.  bit 1 ? toie0: timer/counter0 overflow interrupt enable when the toie0 bit is set (one) and the i-bit in the status register is set (one), the timer/counter0 overflow interrupt is enabled. the corresponding interrupt (at vector $006) is executed if an overflow in timer/counter0 occurs (i.e., when the tov0 bit is set in the timer/counter interrupt flag register [tifr]).  bit 0 ? res: reserved bit this bit is a reserved bit in the at90s2313 and always read as zero. timer/counter interrupt flag register ? tifr  bit 7 ? tov1: timer/counter1 overflow flag the tov1 is set (one) when an overflow occurs in timer/counter1. tov1 is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, tov1 is cleared by writing a logical ? 1 ? to the flag. when the i-bit in sreg and toie1 (timer/counter1 overflow interrupt enable) and tov1 are set (one), the timer/counter1 overflow interrupt is executed. in pwm mode, this bit is set when timer/counter1 changes counting direction at $0000.  bit 6 ? ocf1a: output compare flag 1a the ocf1a bit is set (one) when a compare match occurs between the timer/counter1 and the data in ocr1a (output compare register1 a). ocf1a is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, ocf1a is cleared by writing a logical ? 1 ? to the flag. when the i-bit in sreg and ocie1a (timer/counter1 compare match interrupt enable) and the ocf1a are set (one), the timer/counter1 compare match interrupt is executed.  bits 5, 4 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read as zero.  bit 3 ? icf1: input capture flag 1 the icf1 bit is set (one) to flag an input capture event, indicating that the timer/counter1 value has been transferred to the input capture register (icr1). icf1 is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, icf1 is cleared by writing a logical ? 1 ? to the flag. when the sreg i-bit and ticie1 (timer/counter1 input capture interrupt enable) and icf1 are set (one), the timer/counter1 capture interrupt is executed. bit 7 6 5 4 3 2 1 0 $38 ($58) tov1 ocf1a ? ? icf1 ? tov0 ? tifr read/write r/w r/w r r r/w r r/w r initial value 0 0 0 0 0 0 0 0
25 at90s2313 0839i ? avr ? 06/02  bit 2 ? res: reserved bit this bit is a reserved bit in the at90s2313 and always reads as zero.  bit 1 ? tov0: timer/counter0 overflow flag the bit tov0 is set (one) when an overflow occurs in timer/counter0. tov0 is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, tov0 is cleared by writing a logical ? 1 ? to the flag. when the sreg i-bit and toie0 (timer/counter0 overflow interrupt enable) and tov0 are set (one), the timer/counter0 overflow interrupt is executed.  bit 0 ? res: reserved bit this bit is a reserved bit in the at90s2313 and always reads as zero. external interrupts the external interrupts are triggered by the int1 and int0 pins. observe that, if enabled, the interrupts will trigger even if the int0/int1 pins are configured as outputs. this feature provides a way of generating a software interrupt. the external interrupts can be triggered by a falling or rising edge or a low level. this is set up as indicated in the specification for the mcu control register (mcucr). when the external interrupt is enabled and is configured as level-triggered, the interrupt will trigger as long as the pin is held low. the external interrupts are set up as described in the specification for the mcu control register (mcucr). interrupt response time the interrupt execution response for all the enabled avr interrupts is four clock cycles, minimum. four clock cycles after the interrupt flag has been set, the program vector address for the actual interrupt handling routine is executed. during this four clock cycle period, the program counter (two bytes) is pushed onto the stack, and the stack pointer is decremented by two. the power-down is normally a relative jump to the inter- rupt routine, and this jump takes two clock cycles. if an interrupt occurs during execution of a multi-cycle instruction, this instruction is completed before the interrupt is served . a return from an interrupt handling routine takes four clock cycles. during these four clock cycles, the program counter (two bytes) is popped back from the stack, the stack pointer is incremented by two, and the i-flag in sreg is set. when the avr exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. mcu control register ? mcucr the mcu control register contains control bits for general mcu functions.  bits 7, 6 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read as zero.  bit 5 ? se: sleep enable the se bit must be set (one) to make the mcu enter the sleep mode when the sleep instruction is executed. to avoid the mcu entering the sleep mode unless it is the pro- grammer ? s purpose, it is recommended to set the sleep enable (se) bit just before the execution of the sleep instruction. bit 76543210 $35 ($55) ? ? se sm isc11 isc10 isc01 isc00 mcucr read/write r r r/w r/w r/w r/w r/w r/w initialvalue00000000
26 at90s2313 0839i ? avr ? 06/02  bit 4 ? sm: sleep mode this bit selects between the two available sleep modes. when sm is cleared (zero), idle mode is selected as sleep mode. when sm is set (one), power-down mode is selected as sleep mode. for details, refer to the paragraph ? sleep modes ? . bits3,2?isc11,isc10:interruptsensecontrol1bit1andbit0 the external interrupt 1 is activated by the external pin int1 if the sreg i-flag and the corresponding interrupt mask in the gimsk register is set. the level and edges on the external int1 pin that activate the interrupt are defined in table 5.  bits 1, 0 ? isc01, isc00: interrupt sense control 0 bit 1 and bit 0 the external interrupt 0 is activated by the external pin int0 if the sreg i-flag and the corresponding interrupt mask is set. the level and edges on the external int0 pin that activate the interrupt are defined in table 6. the value on the intn pin is sampled before detecting edges. if edge interrupt is selected, pulses with a duration longer than one cpu clock period will generate an inter- rupt. shorter pulses are not guaranteed to generate an interrupt. if low-level interrupt is selected, the low level must be held until the completion of the currently executing instruction to generate an interrupt. if enabled, a level-triggered interrupt will generate an interrupt request as long as the pin is held low. ta ble 5. interrupt 1 sense control isc11 isc10 description 0 0 the low level of int1 generates an interrupt request. 01reserved 1 0 the falling edge of int1 generates an interrupt request. 1 1 the rising edge of int1 generates an interrupt request. ta ble 6. interrupt 0 sense control isc01 isc00 description 0 0 the low level of int0 generates an interrupt request. 01reserved 1 0 the falling edge of int0 generates an interrupt request. 1 1 the rising edge of int0 generates an interrupt request.
27 at90s2313 0839i ? avr ? 06/02 sleep modes to enter the sleep modes, the se bit in mcucr must be set (one) and a sleep instruc- tion must be executed. if an enabled interrupt occurs while the mcu is in a sleep mode, the mcu awakes, executes the interrupt routine, and resumes execution from the instruction following sleep. the contents of the register file, sram and i/o memory are unaltered. if a reset occurs during sleep mode, the mcu wakes up and executes from the reset vector. idle mode when the sm bit is cleared (zero), the sleep instruction forces the mcu into the idle mode, stopping the cpu but allowing timer/counters, watchdog and the interrupt sys- tem to continue operating. this enables the mcu to wake up from external triggered interrupts as well as internal ones like timer overflow interrupt and watchdog reset. if wake-up from the analog comparator interrupt is not required, the analog comparator can be powered down by setting the acd-bit in the analog comparator control and sta- tus register (acsr). this will reduce power consumption in idle mode. when the mcu wakes up from idle mode, the cpu starts program execution immediately. power-down mode when the sm bit is set (one), the sleep instruction forces the mcu into the power- down mode. in this mode, the external oscillator is stopped while the external interrupts and the watchdog (if enabled) continue operating. only an external reset, a watchdog reset (if enabled), an external level interrupt on int0 or int1 can wake up the mcu. note that when a level-triggered interrupt is used for wake-up from power-down, the low level must be held for a time longer than the reset delay time-out period t tout .other- wise, the device will not wake up. timer/counters the at90s2313 provides two general purpose timer/counters ? one 8-bit t/c and one 16-bit t/c. the timer/counters have individual prescaling selection from the same 10- bit prescaling timer. both timer/counters can either be used as a timer with an internal clock time base or as a counter with an external pin connection that triggers the counting. timer/counter prescaler figure 28 shows the general timer/counter prescaler. figure 28. timer/counter prescaler tck1 tck0
28 at90s2313 0839i ? avr ? 06/02 the four different prescaled selections are: ck/8, ck/64, ck/256, and ck/1024, where ck is the oscillator clock. for the two timer/counters, added selections such as ck, external clock source and stop can be selected as clock sources. 8-bit timer/counter0 figure 29 shows the block diagram for timer/counter0. the 8-bit timer/counter0 can select clock source from ck, prescaled ck or an external pin. in addition, it can be stopped as described in the specification for the timer/counter0 control register (tccr0). the overflow status flag is found in the timer/counter interrupt flag register (tifr). control signals are found in the timer/counter0 control register (tccr0). the interrupt enable/disable settings for timer/counter0 are found in the timer/counter interrupt mask register (timsk). when timer/counter0 is externally clocked, the external signal is synchronized with the oscillator frequency of the cpu. to assure proper sampling of the external clock, the minimum time between two external clock transitions must be at least one internal cpu clock period. the external clock signal is sampled on the rising edge of the internal cpu clock. the 8-bit timer/counter0 features both a high-resolution and a high-accuracy usage with the lower prescaling opportunities. similarly, the high prescaling opportunities make the timer/counter0 useful for lower speed functions or exact timing functions with infre- quent actions. figure 29. timer/counter0 block diagram t0
29 at90s2313 0839i ? avr ? 06/02 timer/counter0 control register ? tccr0  bits 7..3 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read zero.  bits 2,1,0 ? cs02, cs01, cs00: clock select0, bit 2,1 and 0 the clock select0 bits 2, 1, and 0 define the prescaling source of timer/counter0. the stop condition provides a timer enable/disable function. the ck down divided modes are scaled directly from the ck oscillator clock. if the external pin modes are used for timer/counter0, transitions on pd4/(t0) will clock the counter even if the pin is configured as an output. this feature can give the user software control of the counting. timer/counter0 ? tcnt0 the timer/counter0 is realized as an up-counter with read and write access. if the timer/counter0 is written and a clock source is present, the timer/counter0 continues counting in the timer clock cycle following the write operation. bit 7 6 5 4 3 2 1 0 $33 ($53) ?? ? ? ? cs02 cs01 cs00 tccr0 read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 ta ble 7. clock 0 prescale select cs02 cs01 cs00 description 0 0 0 stop, the timer/counter0 is stopped. 001ck 010ck/8 011ck/64 100ck/256 1 0 1 ck/1024 1 1 0 external pin t0, falling edge 1 1 1 external pin t0, rising edge bit 76543210 $32 ($52) msb lsb tcnt0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000
30 at90s2313 0839i ? avr ? 06/02 16-bit timer/counter1 figure 30 shows the block diagram for timer/counter1. figure 30. timer/counter1 block diagram the 16-bit timer/counter1 can select clock source from ck, prescaled ck or an exter- nal pin. in addition, it can be stopped as described in the specification for the timer/counter1 control register (tccr1b). the different status flags (overflow, com- pare match and capture event) and control signals are found in the timer/counter interrupt flag register (tifr). the interrupt enable/disable settings for timer/counter1 are found in the timer/counter interrupt mask register (timsk). when timer/counter1 is externally clocked, the external signal is synchronized with the oscillator frequency of the cpu. to assure proper sampling of the external clock, the minimum time between two external clock transitions must be at least one internal cpu clock period. the external clock signal is sampled on the rising edge of the internal cpu clock. the 16-bit timer/counter1 features both a high-resolution and a high-accuracy usage with the lower prescaling opportunities. similarly, the high prescaling opportunities makes the timer/counter1 useful for lower speed functions or exact timing functions with infrequent actions. the timer/counter1 supports an output compare function using the output compare register 1a (ocr1a) as the data source to be compared to the timer/counter1 con- tents. the output compare functions include optional clearing of the counter on compare matches, and actions on the output compare pin 1 on compare matches. t1
31 at90s2313 0839i ? avr ? 06/02 timer/counter1 can also be used as an 8-, 9-, or 10-bit pulse width modulator. in this mode the counter and the ocr1 register serve as a glitch-free standalone pwm with centered pulses. refer to page 35 for a detailed description of this function. the input capture function of timer/counter1 provides a capture of the timer/counter1 contents to the input capture register (icr1), triggered by an external event on the input capture pin (icp). the actual capture event settings are defined by the timer/counter1 control register (tccr1b). in addition, the analog comparator can be set to trigger the input capture. refer to ? analog comparator ? on page 48 for details on this. the icp pin logic is shown in figure 31. figure 31. icp pin schematic diagram if the noise canceler function is enabled, the actual trigger condition for the capture event is monitored over four samples, and all four must be equal to activate the capture flag. timer/counter1 control register a ? tccr1a  bits 7, 6 ? com1a1, com1a0: compare output mode1, bits 1 and 0 the com1a1 and com1a0 control bits determine any output pin action following a compare match in timer/counter1. any output pin actions affect pin oc1 (output com- pare pin 1) (pb3). this is an alternative function to the i/o port, and the corresponding direction control bit must be set (one) to control an output pin. the control configuration is shown in table 8. notes: 1. in pwm mode, these bits have a different function. refer to table 12 for a detailed description. 2. the initial state of the oc1 output line is undefined.  bits 5..2 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read zero. bit 7 6 5 4 3 2 1 0 $2f ($4f) com1a1 com1a0 ???? pwm11 pwm10 tccr1a read/write r/w r/w r r r r r/w r/w initial value 0 0 0 0 0 0 0 0 ta ble 8. compare 1 mode select (1)(2) com1a1 com1a0 description 0 0 timer/counter1 disconnected from output pin oc1 0 1 toggle the oc1 output line. 1 0 clear the oc1 output line (to zero). 1 1 set the oc1 output line (to one).
32 at90s2313 0839i ? avr ? 06/02  bits 1, 0 ? pwm11, pwm10: pulse width modulator select bits these bits select pwm operation of timer/counter1 as specified in table 9. this mode is described on page 35. timer/counter1 control register b ? tccr1b  bit 7 ? icnc1: input capture1 noise canceler (4 cks) when the icnc1 bit is cleared (zero), the input capture trigger noise canceler function is disabled. the input capture is triggered at the first rising/falling edge sampled on the icp (input capture pin) as specified. when the icnc1 bit is set (one), four successive sam- ples are measured on the icp (input capture pin), and all samples must be high/low according to the input capture trigger specification in the ices1 bit. the actual sampling frequency is the xtal clock frequency.  bit 6 ? ices1: input capture1 edge select while the ices1 bit is cleared (zero), the timer/counter1 contents are transferred to the input capture register (icr1) on the falling edge of the input capture pin (icp). while the ices1 bit is set (one), the timer/counter1 contents are transferred to the input cap- ture register (icr1) on the rising edge of the input capture pin (icp).  bits 5, 4 ? res: reserved bits these bits are reserved bits in the at90s2313 and always read zero.  bit 3 ? ctc1: clear timer/counter1 on compare match when the ctc1 control bit is set (one), the timer/counter1 is reset to $0000 in the clock cycle after a comparea match. if the ctc1 control bit is cleared, timer/counter1 contin- ues counting and is unaffected by a compare match. since the compare match is detected in the cpu clock cycle following the match, this function will behave differently when a prescaling higher than 1 is used for the timer. when a prescaling of 1 is used, and the compare a register is set to c, the timer will count as follows if ctc1 is set: ...|c-2|c-1|c|0|1|... when the prescaler is set to divide by 8, the timer will count like this: ... | c-2, c-2, c-2, c-2, c-2, c-2, c-2, c-2 | c-1, c-1, c-1, c-1, c-1, c-1, c-1, c-1 | c, 0, 0, 0, 0, 0, 0, 0 |... in pwm mode, this bit has no effect. ta ble 9. pwm mode select pwm11 pwm10 description 0 0 pwm operation of timer/counter1 is disabled 0 1 timer/counter1 is an 8-bit pwm 1 0 timer/counter1 is a 9-bit pwm 1 1 timer/counter1 is a 10-bit pwm bit 7654 3210 $2e ($4e) icnc1 ices1 ?? ctc1 cs12 cs11 cs10 tccr1b read/write r/w r/w r r r/w r/w r/w r/w initialvalue0000 0000
33 at90s2313 0839i ? avr ? 06/02  bits 2,1,0 ? cs12, cs11, cs10: clock select1, bits 2, 1 and 0 the clock select1 bits 2, 1, and 0 define the prescaling source of timer/counter1. the stop condition provides a timer enable/disable function. the ck down divided modes are scaled directly from the ck oscillator clock. if the external pin modes are used for timer/counter1, transitions on pd5/(t1) will clock the counter even if the pin is configured as an output. this feature can give the user software control of the counting. timer/counter1 ? tcnt1h and tcnt1l this 16-bit register contains the prescaled value of the 16-bit timer/counter1. to ensure that both the high and low bytes are read and written simultaneously when the cpu accesses these registers, the access is performed using an 8-bit temporary regis- ter (temp). this temporary register is also used when accessing ocr1a and icr1. if the main program and interrupt routines perform access to registers using temp, inter- rupts must be disabled during access from the main program or interrupts if interrupts are re-enabled.  tcnt1 timer/counter1 write: whenthecpuwritestothehighbytetcnt1h,thewrittendataisplacedinthe temp register. next, when the cpu writes the low byte tcnt1l, this byte of data is combined with the byte data in the temp register, and all 16 bits are written to the tcnt1 timer/counter1 register simultaneously. consequently, the high byte tcnt1h must be accessed first for a full 16-bit register write operation.  tcnt1 timer/counter1 read: when the cpu reads the low byte tcnt1l, the data of the low byte tcnt1l is sent to the cpu and the data of the high byte tcnt1h is placed in the temp register. when the cpu reads the data in the high byte tcnt1h, the cpu receives the data in the temp register. consequently, the low byte tcnt1l must be accessed first for a full 16-bit register read operation. table 10. clock 1 prescale select cs12 cs11 cs10 description 0 0 0 stop, the timer/counter1 is stopped. 001ck 010ck/8 011ck/64 100ck/256 1 0 1 ck/1024 1 1 0 external pin t1, falling edge 1 1 1 external pin t1, rising edge bit 151413121110 9 8 $2d ($4d) msb tcnt1h $2c ($4c) lsb tcnt1l 76543210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 00000000
34 at90s2313 0839i ? avr ? 06/02 the timer/counter1 is realized as an up or up/down (in pwm mode) counter with read and write access. if timer/counter1 is written to and a clock source is selected, the timer/counter1 continues counting in the timer clock cycle after it is preset with the writ- ten value. timer/counter1 output compare register a ? ocr1ah and ocr1al the output compare register is a 16-bit read/write register. the timer/counter1 output compare register contains the data to be continuously compared with timer/counter1. actions on compare matches are specified in the timer/counter1 control and status registers. since the output compare register (ocr1a) is a 16-bit register, a temporary register temp is used when ocr1a is written to ensure that both bytes are updated simulta- neously. when the cpu writes the high byte, ocr1ah, the data is temporarily stored in the temp register. when the cpu writes the low byte, ocr1al, the temp register is simultaneously written to ocr1ah. consequently, the high byte ocr1ah must be writ- ten first for a full 16-bit register write operation. the temp register is also used when accessing tcnt1, and icr1. if the main pro- gram and interrupt routines perform access to registers using temp, interrupts must be disabled during access from the main program or interrupts if interrupts are re-enabled. timer/counter1 input capture register ? icr1h and icr1l the input capture register is a 16-bit read-only register. when the rising or falling edge (according to the input capture edge setting [ices1]) of the signal at the input capture pin (icp) is detected, the current value of the timer/counter1 is transferred to the input capture register (icr1). at the same time, the input capture flag (icf1) is set (one). since the input capture register (icr1) is a 16-bit register, a temporary register temp is used when icr1 is read to ensure that both bytes are read simultaneously. when the cpu reads the low byte icr1l, the data is sent to the cpu and the data of the high byte icr1h is placed in the temp register. when the cpu reads the data in the high byte icr1h, the cpu receives the data in the temp register. consequently, the low byte icr1l must be accessed first for a full 16-bit register read operation. bit 151413121110 9 8 $2b ($4b) msb ocr1ah $2a ($4a) lsb ocr1al 76543210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 00000000 bit 151413121110 9 8 $25 ($45) msb icr1h $24 ($44) lsb icr1l 76543210 read/write r r rrrrrr rrrrrrrr initialvalue00000000 00000000
35 at90s2313 0839i ? avr ? 06/02 the temp register is also used when accessing tcnt1 and ocr1a. if the main pro- gram and interrupt routines perform access to registers using temp, interrupts must be disabled during access from the main program or interrupts if interrupts are re-enabled. timer/counter1 in pwm mode when the pwm mode is selected, timer/counter1 and the output compare register1 (ocr1a) form an 8-, 9-, or 10-bit, free-running, glitch-free and phase-correct pwm with output on the pb3(oc1) pin. timer/counter1 acts as an up/down counter, counting up from $0000 to top (see table 11), where it turns and counts down again to zero before the cycle is repeated. when the counter value matches the contents of the 8, 9 or 10 least significant bits of ocr1a, the pb3(oc1) pin is set or cleared according to the set- tings of the com1a1 and com1a0 bits in the timer/counter1 control register (tccr1). refer to table 12 for details. note: 1. the initial state of the oc1 output line is undefined. note that in the pwm mode, the 10 least significant ocr1a bits, when written, are transferred to a temporary location. they are latched when timer/counter1 reaches top. this prevents the occurrence of odd-length pwm pulses (glitches) in the event of an unsynchronized ocr1a write. see figure 32 for an example. figure 32. effects on unsynchronized ocr1 latching table 11. timer top values and pwm frequency pwm resolution timer top value frequency 8-bit $00ff (255) f tc1 /510 9-bit $01ff (511) f tc1 /1022 10-bit $03ff(1023) f tc1 /2046 table 12. compare1 mode select in pwm mode (1) com1a1 com1a0 effect on oc1 0 0 not connected 0 1 not connected 10 cleared on compare match, upcounting. set on compare match, down-counting (non-inverted pwm). 11 cleared on compare match, downcounting. set on compare match, up-counting (inverted pwm). compare v alue changes compare value changes
36 at90s2313 0839i ? avr ? 06/02 during the time between the write and the latch operations, a read from ocr1a will read the contents of the temporary location. this means that the most recently written value always will read out of ocr1a. when the ocr1 contains $0000 or top, the output oc1 is updated to low or high on the next compare match according to the settings of com1a1/com1a0. this is shown in table 13. note: if the compare register contains the top value and the prescaler is not in use (cs12..cs10 = 001), the pwm output will not produce any pulse at all, because the up- counting and down-counting values are reached simultaneously. when the prescaler is in use (cs12..cs10 001 or 000), the pwm output goes active when the counter reaches the top value, but the down-counting compare match is not interpreted to be reached before the next time the counter reaches the top value, making a one-period pwm pulse. in pwm mode, the timer overflow flag1 (tov1) is set when the counter advances from $0000. timer overflow interrupt1 operates exactly as in normal timer/counter mode (i.e., it is executed when tov1 is set, provided that timer overflow interrupt1 and global interrupts are enabled). this also applies to the timer output compare1 flag and interrupt. table 13. pwm outputs ocr = $0000 or top com1a1 com1a0 ocr1a output oc1 1 0 $0000 l 10toph 1 1 $0000 h 11topl
37 at90s2313 0839i ? avr ? 06/02 watchdog timer the watchdog timer is clocked from a separate on-chip oscillator that runs at 1 mhz. this is the typical value at v cc = 5v. see characterization data for typical values at other v cc levels. by controlling the watchdog timer prescaler, the watchdog reset interval can be adjusted. see table 14 for a detailed description. the wdr (watchdog reset) instruction resets the watchdog timer. eight different clock cycle periods can be selected to determine the reset period. if the reset period expires without another watchdog reset, the at90s2313 resets and executes from the reset vector. for tim- ing details on the watchdog reset, refer to page 21. to prevent unintentional disabling of the watchdog, a special turn-off sequence must be followed when the watchdog is disabled. refer to the description of the watchdog timer control register for details. figure 33. watchdog timer watchdog timer control register ? wdtcr  bits 7..5 ? res: reserved bits these bits are reserved bits in the at90s2313 and will always read as zero.  bit 4 ? wdtoe: watchdog turn-off enable this bit must be set (one) when the wde bit is cleared. otherwise, the watchdog will not be disabled. once set, hardware will clear this bit to zero after four clock cycles. refer to the description of the wde bit for a watchdog disable procedure.  bit 3 ? wde: watchdog enable when the wde is set (one) the watchdog timer is enabled, and if the wde is cleared (zero), the watchdog timer function is disabled. wde can only be cleared if the wdtoe bit is set (one). to disable an enabled watchdog timer, the following proce- dure must be followed: bit 765 4 3210 $21 ($41) ??? wdtoe wde wdp2 wdp1 wdp0 wdtcr read/write r r r r/w r/w r/w r/w r/w initialvalue000 0 0000
38 at90s2313 0839i ? avr ? 06/02 1. in the same operation, write a logical ? 1 ? to wdtoe and wde. a logical ? 1 ? must be written to wde even though it is set to 1 before the disable operation starts. 2. within the next four clock cycles, write a logical ? 0 ? to wde. this disables the watchdog.  bits 2..0 ? wdp2, wdp1, wdp0: watchdog timer prescaler 2, 1 and 0 the wdp2, wdp1 and wdp0 bits determine the watchdog timer prescaling when the watchdog timer is enabled. the different prescaling values and their corresponding time-out periods are shown in table 14. note: 1. the frequency of the watchdog oscillator is voltage-dependent, as shown in the electrical characteristics section. the wdr (watchdog reset) instruction should always be executed before the watchdog timer is enabled. this ensures that the reset period will be in accordance with the watchdog timer prescale settings. if the watchdog timer is enabled without reset, the watchdog timer may not start counting from zero. to avoid unintentional mcu reset, the watchdog timer should be disabled or reset before changing the watchdog timer prescale select. table 14. watchdog timer prescale select (1) wdp2 wdp1 wdp0 number of wdt oscillator cycles typical time-out at v cc =3.0v typical time-out at v cc =5.0v 0 0 0 16k cycles 47 ms 15 ms 0 0 1 32k cycles 94 ms 30 ms 0 1 0 64k cycles 0.19 s 60 ms 0 1 1 128k cycles 0.38 s 0.12 s 1 0 0 256k cycles 0.75 s 0,24 s 1 0 1 512k cycles 1.5 s 0.49 s 1 1 0 1,024k cycles 3.0 s 0.97 s 1 1 1 2,048k cycles 6.0 s 1.9 s
39 at90s2313 0839i ? avr ? 06/02 eeprom read/write access the eeprom access registers are accessible in the i/o space. the write access time is in the range of 2.5 - 4 ms, depending on the v cc voltages. a self-timing function, however, lets the user software detect when the next byte can be written. if the user code contains code that writes the eeprom, some precaution must be taken. in heavily filtered power supplies, v cc is likely to rise or fall slowly on power- up/down. this causes the device for some period of time to run at a voltage lower than specified as minimum for the clock frequency used. cpu operation under these condi- tions may cause the program counter to perform unintentional jumps and eventually execute the eeprom write code. to secure eeprom integrity, the user is advised to use an external under-voltage reset circuit in this case. in order to prevent unintentional eeprom writes, a specific write procedure must be fol- lowed. refer to the description of the eeprom control register for details on this. when the eeprom is written, the cpu is halted for two clock cycles before the next instruction is executed. when the eeprom is read, the cpu is halted for four clock cycles before the next instruction is executed. eeprom address register ? eear  bit 7 ? res: reserved bit this bit is a reserved bit in the at90s2313 and will always read as zero.  bit 6..0 ? eear6..0: eeprom address the eeprom address register (eear6..0) specifies the eeprom address in the 128 bytes eeprom space. the eeprom data bytes are addressed linearly between 0 and 127. eeprom data register ? eedr  bit 7..0 ? eedr7..0: eeprom data for the eeprom write operation, the eedr register contains the data to be written to the eeprom in the address given by the eear register. for the eeprom read oper- ation, the eedr contains the data read out from the eeprom at the address given by eear. bit 76543210 $1e ($3e) ? eear6 eear5 eear4 eear3 eear2 eear1 eear0 eear read/write r r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $1d ($3d) msb lsb eedr read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000
40 at90s2313 0839i ? avr ? 06/02 eeprom control register ? eecr  bit 7..3 ? res: reserved bits these bits are reserved bits in the at90s2313 and will always read as zero.  bit 2 ? eemwe: eeprom master write enable the eemwe bit determines whether setting eewe to one causes the eeprom to be written. when eemwe is set (one), setting eewe will write data to the eeprom at the selected address. if eemwe is zero, setting eewe will have no effect. when eemwe has been set (one) by software, hardware clears the bit to zero after four clock cycles. see the description of the eewe bit for a eeprom write procedure.  bit 1 ? eewe: eeprom write enable the eeprom write enable signal (eewe) is the write strobe to the eeprom. when address and data are correctly set up, the eewe bit must be set to write the value into the eeprom. the eemwe bit must be set when the logical ? 1 ? iswrittentoeewe,oth- erwise no eeprom write takes place. the following procedure should be followed when writing the eeprom (the order of steps 2 and 3 is unessential): 1. wait until eewe becomes zero. 2. write new eeprom address to eear (optional). 3. write new eeprom data to eedr (opti onal). 4. write a logical ? 1 ? to the eemwe bit in eecr (to be able to write a logical ? 1 ? to theeemwebit,theeewebitmustbewrittentozerointhesamecycle). 5. within four clock cycles after setting eemwe, write a logical ? 1 ? to eewe. when the write access time (typically 2.5 ms at v cc =5vor4msatv cc =2.7v)has elapsed, the eewe bit is cleared (zero) by hardware. the user software can poll this bit and wait for a zero before writing the next byte. when eewe has been set, the cpu is halted for two cycles before the next instruction is executed. caution: an interrupt between step 4 and step 5 will make the write cycle fail, since the eeprom master write enable will time-out. if an interrupt routine accessing the eeprom is interrupting another eeprom access, the eear or eedr register will be modified, causing the interrupted eeprom access to fail. it is recommended to have the global interrupt flag cleared during the last four steps to avoid these problems.  bit 0 ? eere: eeprom read enable the eeprom read enable signal (eere) is the read strobe to the eeprom. when the correct address is set up in the eear register, the eere bit must be set. when the eere bit is cleared (zero) by hardware, requested data is found in the eedr register. the eeprom read access takes one instruction and there is no need to poll the eere bit. when eere has been set, the cpu is halted for four cycles before the next instruc- tion is executed. the user should poll the eewe bit before starting the read operation. if a write operation is in progress when new data or address is written to the eeprom i/o registers, the write operation will be interrupted and the result is undefined. bit 76543 2 10 $1c ($3c) ????? eemwe eewe eere eecr read/write r rrrrr/wr/wr/w initialvalue00000 0 00
41 at90s2313 0839i ? avr ? 06/02 prevent eeprom corruption during periods of low v cc , the eeprom data can be corrupted because the supply volt- age is too low for the cpu and the eeprom to operate properly. these issues are the same as for board-level systems using the eeprom, and the same design solutions should be applied. an eeprom data corruption can be caused by two situations when the voltage is too low. first, a regular write sequence to the eeprom requires a minimum voltage to operate correctly. secondly, the cpu itself can execute instructions incorrectly if the supply voltage for executing instructions is too low. eeprom data corruption can easily be avoided by following these design recommen- dations (one is sufficient): 1. keep the avr reset active (low) during periods of insufficient power supply voltage. this is best done by an external low v cc reset protection circuit, often referred to as a brown-out detector (bod). please refer to the avr 180 applica- tion note for design considerations regarding power-on reset and low-voltage detection. 2. keep the avr core in power-down sleep mode during periods of low v cc .this will prevent the cpu from attempting to decode and execute instructions, effec- tively protecting the eeprom registers from unintentional writes. 3. store constants in flash memory if the ability to change memory contents from software is not required. flash memory cannot be updated by the cpu and will not be subject to corruption.
42 at90s2313 0839i ? avr ? 06/02 uart the at90s2313 features a full duplex (separate receive and transmit registers) uni- versal asynchronous receiver and transmitter (uart). the main features are:  baud rate generator that can generate a large number of baud rates (bps)  high baud rates at low xtal frequencies  8 or 9 bits data  noise filtering  overrun detection  framing error detection  false start bit detection  three separate interrupts on tx complete, tx data register empty and rx complete data transmission a block schematic of the uart transmitter is shown in figure 34. data transmission is initiated by writing the data to be transmitted to the uart i/o data register (udr). data is transferred from udr to the transmit shift register when:  a new character has been written to udr after the stop bit from the previous character has been shifted out. the shift register is loaded immediately.  a new character has been written to udr before the stop bit from the previous character has been shifted out. the shift register is loaded when the stop bit of the character currently being transmitted has been shifted out. figure 34. uart transmitter if the 10(11)-bit transmitter shift register is empty, data is transferred from udr to the shift register. at this time the udre (uart data register empty) bit in the uart sta-
43 at90s2313 0839i ? avr ? 06/02 tus register (usr) is set. when this bit is set (one), the uart is ready to receive the next character. at the same time as the data is transferred from udr to the 10(11)-bit shift register, bit 0 of the shift register is cleared (start bit) and bit 9 or 10 is set (stop bit). if 9-bit data word is selected (the chr9 bit in the uart control register [ucr] is set), the txb8 bit in ucr is transferred to bit 9 in the transmit shift register. on the baud rate clock following the transfer operation to the shift register, the start bit is shifted out on the txd pin. then follows the data, lsb first. when the stop bit has been shifted out, the shift register is loaded if any new data has been written to the udr during the transmission. during loading, udre is set. if there is no new data in the udr register to send when the stop bit is shifted out, the udre flag will remain set until udr is written again. when no new data has been written, and the stop bit has been present on txd for one bit length, the tx complete flag (txc) in usr is set. the txen bit in ucr enables the uart transmitter when set (one). when this bit is cleared (zero), the pd1 pin can be used for general i/o. when txen is set, the uart transmitter will be connected to pd1, which is forced to be an output pin regardless of the setting of the ddd1 bit in ddrd. data reception figure 35 shows a block diagram of the uart receiver. figure 35. uart receiver the receiver front-end logic samples the signal on the rxd pin at a frequency of 16 times the baud rate. while the line is idle, one single sample of logical ? 0 ? will be inter- preted as the falling edge of a start bit, and the start bit detection sequence is initiated. let sample 1 denote the first zero-sample. following the 1-to-0 transition, the receiver samples the rxd pin at samples 8, 9 and 10. if two or more of these three samples are
44 at90s2313 0839i ? avr ? 06/02 found to be logical ? 1 ? s, the start bit is rejected as a noise spike and the receiver starts looking for the next 1-to-0 transition. if, however, a valid start bit is detected, sampling of the data bits following the start bit is performed. these bits are also sampled at samples 8, 9 and 10. the logical value found in at least two of the three samples is taken as the bit value. all bits are shifted into the transmitter shift register as they are sampled. sampling of an incoming character is shown in figure 36. figure 36. sampling received data when the stop bit enters the receiver, the majority of the three samples must be ? 1 ? to accept the stop bit. if two or more samples are logical ? 0 ? s, the framing error (fe) flag in the uart status register (usr) is set. before reading the udr register, the user should always check the fe bit to detect framing errors. whether or not a valid stop bit is detected at the end of a character-reception cycle, the data is transferred to udr and the rxc flag in usr is set. udr is in fact two physically separate registers; one for transmitted data and one for received data. when udr is read, the receive data register is accessed, and when udr is written, the transmit data register is accessed. if 9-bit data word is selected (the chr9 bit in the uart con- trol register [ucr] is set), the rxb8 bit in ucr is loaded with bit 9 in the transmit shift register when data is transferred to udr. if, after having received a character, the udr register has not been read since the last receive, the overrun (or) flag in ucr is set. this means that the last data byte shifted into the shift register could not be transferred to udr and has been lost. the or bit is buffered and is updated when the valid data byte in udr is read. thus, the user should always check the or bit after reading the udr register in order to detect any overruns if the baud rate is high or cpu load is high. when the rxen bit in the ucr register is cleared (zero), the receiver is disabled. this means that the pd0 pin can be used as a general i/o pin. when rxen is set, the uart receiver will be connected to pd0, which is forced to be an input pin regardless of the setting of the ddd0 bit in ddrd. when pd0 is forced to input by the uart, the portd0 bit can still be used to control the pull-up resistor on the pin. when the chr9 bit in the ucr register is set, transmitted and received characters are nine bits long plus start and stop bits. the ninth data bit to be transmitted is the txb8 bit in ucr register. this bit must be set to the wanted value before a transmission is initi- ated by writing to the udr register. the ninth data bit received is the rxb8 bit in the ucr register.
45 at90s2313 0839i ? avr ? 06/02 uart control the uart i/o data register ? udr the udr register is actually two physically separate registers sharing the same i/o address. when writing to the register, the uart transmit data register is written. when reading from udr, the uart receive data register is read. uart status register ? usr the usr register is a read-only register providing information on the uart status.  bit 7 ? rxc: uart receive complete this bit is set (one) when a received character is transferred from the receiver shift register to udr. the bit is set regardless of any detected framing errors. when the rxcie bit in ucr is set, the uart receive complete interrupt will be executed when rxc is set (one). rxc is cleared by reading udr. when interrupt-driven data reception is used, the uart receive complete interrupt routine must read udr in order to clear rxc, otherwise a new interrupt will occur once the interrupt routine terminates.  bit 6 ? txc: uart transmit complete this bit is set (one) when the entire character (including the stop bit) in the transmit shift register has been shifted out and no new data has been written to udr. this flag is especially useful in half-duplex communications interfaces, where a transmitting appli- cation must enter receive mode and free the communications bus immediately after completing the transmission. when the txcie bit in ucr is set, setting of txc causes the uart transmit complete interrupt to be executed. txc is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, the txc bit is cleared (zero) by writing a logical ? 1 ? to the bit.  bit 5 ? udre: uart data register empty this bit is set (one) when a character written to udr is transferred to the transmit shift register. setting of this bit indicates that the transmitter is ready to receive a new char- acter for transmission. when the udrie bit in ucr is set, the uart transmit complete interrupt is executed as long as udre is set. udre is cleared by writing udr. when interrupt-driven data transmittal is used, the uart data register empty interrupt routine must write udr in order to clear udre, otherwise a new interrupt will occur once the interrupt routine terminates. udre is set (one) during reset to indicate that the transmitter is ready. bit 76543210 $0c ($2c) msb lsb udr read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $0b ($2b) rxc txc udre fe or ??? usr read/write r r/w rrrrrr initialvalue00100000
46 at90s2313 0839i ? avr ? 06/02  bit 4 ? fe: framing error this bit is set if a framing error condition is detected (i.e., when the stop bit of an incom- ing character is zero). the fe bit is cleared when the stop bit of received data is one.  bit 3 ? or: overrun this bit is set if an overrun condition is detected (i.e., when a character already present in the udr register is not read before the next character has been shifted into the receiver shift register). the or bit is buffered, which means that it will be set once the valid data still in udre is read. the or bit is cleared (zero) when data is received and transferred to udr.  bits 2..0 ? res: reserved bits these bits are reserved bits in the at90s2313 and will always read as zero. uart control register ? ucr  bit 7 ? rxcie: rx complete interrupt enable when this bit is set (one), a setting of the rxc bit in usr will cause the receive com- plete interrupt routine to be executed provided that global interrupts are enabled.  bit 6 ? txcie: tx complete interrupt enable when this bit is set (one), a setting of the txc bit in usr will cause the transmit com- plete interrupt routine to be executed provided that global interrupts are enabled.  bit 5 ? udrie: uart data register empty interrupt enable when this bit is set (one), a setting of the udre bit in usr will cause the uart data register empty interrupt routine to be executed provided that global interrupts are enabled.  bit 4 ? rxen: receiver enable this bit enables the uart receiver when set (one). when the receiver is disabled, the rxc, or and fe status flags cannot become set. if these flags are set, turning off rxen does not cause them to be cleared.  bit 3 ? txen: transmitter enable this bit enables the uart transmitter when set (one). when disabling the transmitter while transmitting a character, the transmitter is not disabled before the character in the shift register plus any following character in udr has been completely transmitted.  bit 2 ? chr9: 9 bit characters when this bit is set (one), transmitted and received characters are nine bits long plus start and stop bits. the ninth bit is read and written by using the rxb8 and txb8 bits in ucr, respectively. the ninth data bit can be used as an extra stop bit or a parity bit. bit 76543210 $0a ($2a) rxcie txcie udrie rxen txen chr9 rxb8 txb8 ucr read/write r/w r/w r/w r/w r/w r/w r w initialvalue00000010
47 at90s2313 0839i ? avr ? 06/02  bit 1 ? rxb8: receive data bit 8 when chr9 is set (one), rxb8 is the ninth data bit of the received character.  bit 0 ? txb8: transmit data bit 8 when chr9 is set (one), txb8 is the ninth data bit in the character to be transmitted. baud rate generator the baud rate generator is a frequency divider that generates baud rates according to the following equation:  baud = baud rate  f ck = crystal clock frequency  ubrr = contents of the uart baud rate register (ubrr) (0 - 255) for standard crystal frequencies, the most commonly used baud rates can be generated by using the ubrr settings in table 15. ubrr values that yield an actual baud rate dif- fering less than 2% from the target baud rate, are boldfaced in the table. however, using baud rates that have more than 1% error is not recommended. high error ratings give less noise resistance. table 15. ubrr settings at various crystal frequencies baud f ck 16(ubrr 1) + ------------------------------------ - = baud rate 1mhz %error 1.8432 mhz %error 2mhz %error 2.4576 mhz %error 2400 ubrr= 25 0.2 ubrr= 47 0.0 ubrr= 51 0.2 ubrr= 63 0.0 4800 ubrr= 12 0.2 ubrr= 23 0.0 ubrr= 25 0.2 ubrr= 31 0.0 9600 ubrr= 6 7.5 ubrr= 11 0.0 ubrr= 12 0.2 ubrr= 15 0.0 14400 ubrr= 3 7.8 ubrr= 70.0 ubrr= 8 3.7 ubrr= 10 3.1 19200 ubrr= 2 7.8 ubrr= 50.0 ubrr= 6 7.5 ubrr= 70.0 28800 ubrr= 1 7.8 ubrr= 30.0 ubrr= 3 7.8 ubrr= 4 6.3 38400 ubrr= 1 22.9 ubrr= 20.0 ubrr= 2 7.8 ubrr= 30.0 57600 ubrr= 0 7.8 ubrr= 10.0 ubrr= 1 7.8 ubrr= 2 12.5 76800 ubrr= 0 22.9 ubrr= 1 33.3 ubrr= 1 22.9 ubrr= 10.0 115200 ubrr= 0 84.3 ubrr= 00.0 ubrr= 0 7.8 ubrr= 0 25.0 baud rate 3.2768 mhz %error 3.6864 mhz %error 4mhz %error 4.608 mhz %error 2400 ubrr= 84 0.4 ubrr= 95 0.0 ubrr= 103 0.2 ubrr= 119 0.0 4800 ubrr= 42 0.8 ubrr= 47 0.0 ubrr= 51 0.2 ubrr= 59 0.0 9600 ubrr= 20 1.6 ubrr= 23 0.0 ubrr= 25 0.2 ubrr= 29 0.0 14400 ubrr= 13 1.6 ubrr= 15 0.0 ubrr= 16 2.1 ubrr= 19 0.0 19200 ubrr= 10 3.1 ubrr= 11 0.0 ubrr= 12 0.2 ubrr= 14 0.0 28800 ubrr= 61.6 ubrr= 70.0 ubrr= 8 3.7 ubrr= 90.0 38400 ubrr= 4 6.3 ubrr= 50.0 ubrr= 6 7.5 ubrr= 7 6.7 57600 ubrr= 3 12.5 ubrr= 30.0 ubrr= 3 7.8 ubrr= 40.0 76800 ubrr= 2 12.5 ubrr= 20.0 ubrr= 2 7.8 ubrr= 3 6.7 115200 ubrr= 1 12.5 ubrr= 10.0 ubrr= 1 7.8 ubrr= 2 20.0 baud rate 7.3728 mhz %error 8mhz %error 9.216 mhz %error 11.059 mhz %error 2400 ubrr= 191 0.0 ubrr= 207 0.2 ubrr= 239 0.0 ubrr= 287 - 4800 ubrr= 95 0.0 ubrr= 103 0.2 ubrr= 119 0.0 ubrr= 143 0.0 9600 ubrr= 47 0.0 ubrr= 51 0.2 ubrr= 59 0.0 ubrr= 71 0.0 14400 ubrr= 31 0.0 ubrr= 34 0.8 ubrr= 39 0.0 ubrr= 47 0.0 19200 ubrr= 23 0.0 ubrr= 25 0.2 ubrr= 29 0.0 ubrr= 35 0.0 28800 ubrr= 15 0.0 ubrr= 16 2.1 ubrr= 19 0.0 ubrr= 23 0.0 38400 ubrr= 11 0.0 ubrr= 12 0.2 ubrr= 14 0.0 ubrr= 17 0.0 57600 ubrr= 70.0 ubrr= 8 3.7 ubrr= 90.0 ubrr= 11 0.0 76800 ubrr= 50.0 ubrr= 6 7.5 ubrr= 7 6.7 ubrr= 80.0 115200 ubrr= 30.0 ubrr= 3 7.8 ubrr= 40.0 ubrr= 50.0
48 at90s2313 0839i ? avr ? 06/02 uart baud rate register ? ubrr the ubrr register is an 8-bit read/write register that specifies the uart baud rate according to the formula on the previous page. analog comparator the analog comparator compares the input values on the positive input ain0 (pb0) and the negative input pb1(ain1). when the voltage on the positive input pb0 (ain0) is higher than the voltage on the negative input pb1 (ain1), the analog comparator out- put, aco is set (one). the comparator ? s output can be set to trigger the timer/counter1 input capture function. in addition, the comparator can trigger a separate interrupt exclusive to the analog comparator. the user can select interrupt triggering on compar- ator output rise, fall or toggle. a block diagram of the comparator and its surrounding logic is shown in figure 37. figure 37. analog comparator block diagram analog comparator control and status register ? acsr  bit 7 ? acd: analog comparator disable when this bit is set (one), the power to the analog comparator is switched off. this bit can be set at any time to turn off the analog comparator. this will reduce power con- sumption in active and idle modes. when changing the acd bit, the analog comparator interrupt must be disabled by clearing the acie bit in acsr. otherwise an interrupt can occur when the bit is changed.  bit 6 ? res: reserved bit this bit is a reserved bit in the at90s2313 and will always read as zero. bit 76543210 $09 ($29) msb lsb ubrr read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $08 ($28) acd ? aco aci acie acic acis1 acis0 acsr read/write r/w r r r/w r/w r/w r/w r/w initialvalue00n/a00000
49 at90s2313 0839i ? avr ? 06/02  bit 5 ? aco: analog comparator output aco is directly connected to the comparator output.  bit 4 ? aci: analog comparator interrupt flag this bit is set (one) when a comparator output event triggers the interrupt mode defined by acis1 and acis0. the analog comparator interrupt routine is executed if the acie bit is set (one) and the i-bit in sreg is set (one). aci is cleared by hardware when exe- cuting the corresponding interrupt handling vector. alternatively, aci is cleared by writing a logical ? 1 ? to the flag. observe, however, that if another bit in this register is modified using the sbi or cbi instruction, aci will be cleared if it has become set before the operation.  bit 3 ? acie: analog comparator interrupt enable when the acie bit is set (one) and the i-bit in the status register is set (one), the ana- log comparator interrupt is activated. when cleared (zero), the interrupt is disabled.  bit 2 ? acic: analog comparator input capture enable when set (one), this bit enables the input capture function in timer/counter1 to be trig- gered by the analog comparator. the comparator output is, in this case, directly connected to the input capture front-end logic, making the comparator utilize the noise canceler and edge-select features of the timer/counter1 input capture interrupt. when cleared (zero), no connection between the analog comparator and the input capture function is given. to make the comparator trigger the timer/counter1 input capture interrupt, the ticie1 bit in the timer interrupt mask register (timsk) must be set (one).  bits 1,0 ? acis1, acis0: analog comparator interrupt mode select these bits determine which comparator events trigger the analog comparator interrupt. the different settings are shown in table 16. note: 1. when changing the acis1/acis0 bits, the analog comparator interrupt must be dis- abled by clearing its interrupt enable bit in the acsr register. otherwise an interrupt can occur when the bits are changed. table 16. acis1/acis0 settings (1) acis1 acis0 interrupt mode 0 0 comparator interrupt on output toggle 01reserved 1 0 comparator interrupt on falling output edge 1 1 comparator interrupt on rising output edge
50 at90s2313 0839i ? avr ? 06/02 i/o ports all avr ports have true read-modify-write functionality when used as general digital i/o ports. this means that the direction of one port pin can be changed without uninten- tionally changing the direction of any other pin with the sbi and cbi instructions. the same applies for changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). port b port b is an 8-bit bi-directional i/o port. three i/o memory address locations are allocated for the port b, one each for the data register ? portb, $18 ($38), data direction register ? ddrb, $17($37) and the port b input pins ? pinb, $16($36). the port b input pins address is read-only, while the data register and the data direction register are read/write. all port pins have individually selectable pull-up resistors. the port b output buffers can sink 20 ma and thus drive led displays directly. when pins pb0 to pb7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resis- tors are activated. the port b pins with alternate functions are shown in table 17. when the pins are used for the alternate function, the ddrb and portb registers have to be set according to the alternate function description. port b data register ? portb port b data direction register ? ddrb port b input pins address ? pinb table 17. port b pin alternate functions port pin alternate functions pb0 ain0 (analog comparator positive input) pb1 ain1 (analog comparator negative input) pb3 oc1 (timer/counter1 output compare match output) pb5 mosi (data input line for memory downloading) pb6 miso (data output line for memory uploading) pb7 sck (serial clock input) bit 76543210 $18 ($38) portb7 portb6 portb5 portb4 portb3 portb2 portb1 portb0 portb read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $17 ($37) ddb7 ddb6 ddb5 ddb4 ddb3 ddb2 ddb1 ddb0 ddrb read/write r/w r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $16 ($36) pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 pinb read/write r r r rrrrr initial value n/a n/a n/a n/a n/a n/a n/a n/a
51 at90s2313 0839i ? avr ? 06/02 the port b input pins address (pinb) is not a register; this address enables access to the physical value on each port b pin. when reading portb, the port b data latch is read, and when reading pinb, the logical values present on the pins are read. port b as general digital i/o all eight pins in port b have equal functionality when used as digital i/o pins. pbn, general i/o pin: the ddbn bit in the ddrb register selects the direction of this pin. if ddbn is set (one), pbn is configured as an output pin. if ddbn is cleared (zero), pbn is configured as an input pin. if portbn is set (one) when the pin is configured as an input pin, the mos pull-up resistor is activated. to switch the pull-up resistor off, the portbn has to be cleared (zero) or the pin has to be configured as an output pin the port b pins are tri-stated when a reset condition becomes active, even if the clock is not active. note: 1. n:7,6 ? 0, pin number. alternate functions of port b the alternate pin functions of port b are:  sck ? port b, bit 7 sck, clock input pin for memory up/downloading.  miso ? port b, bit 6 miso, data output pin for memory uploading.  mosi ? port b, bit 5 mosi, data input pin for memory downloading.  oc1 ? port b, bit 3 oc1, output compare match output. the pb3 pin can serve as an external output for timer1 compare match. the pb3 pin has to be configured as an output (ddb3 is set [one]) to serve this function. see the timer description for further details, and how to enable the output.  ain1 ? port b, bit 1 ain1, analog comparator negative input. when configured as an input (ddb1 is cleared [zero]) and with the internal mos pull-up resistor switched off (pb1 is cleared [zero]), this pin also serves as the negative input of the on-chip analog comparator.  ain0 ? port b, bit 0 ain0, analog comparator positive input. when configured as an input (ddb0 is cleared [zero]) and with the internal mos pull-up resistor switched off (pb0 is cleared [zero]), this pin also serves as the positive input of the on-chip analog comparator. table 18. ddbn effects on port b pins (1) ddbn portbn i/o pull-up comment 0 0 input no tri-state (high-z) 0 1 input yes pbn will source current if ext. pulled low 1 0 output no push-pull zero output 1 1 output no push-pull one output
52 at90s2313 0839i ? avr ? 06/02 port b schematics note that all port pins are synchronized. the synchronization latches are, however, not shown in the figures. figure 38. port b schematic diagram (pins pb0 and pb1)
53 at90s2313 0839i ? avr ? 06/02 figure 39. port b schematic diagram (pin pb3) figure 40. port b schematic diagram (pins pb2 and pb4) pb3 ddb3 mos pull- up reset r q d c rd wd wp com1a0 com1a1 comp. match1 output mode select reset r q d c portb3 rl rp wp: write portb wd: write ddrb rl: read portb latch rp: read portb pin rd: read ddrb data bus
54 at90s2313 0839i ? avr ? 06/02 figure 41. port b schematic diagram (pin pb5) figure 42. port b schematic diagram (pin pb6)
55 at90s2313 0839i ? avr ? 06/02 figure 43. port b schematic diagram (pin pb7) port d three i/o memory address locations are allocated for the port d: one each for the data register ? portd, $12($32), data direction register ? ddrd, $11($31) and the port d input pins ? pind, $10($30). the port d input pins address is read-only, while the data register and the data direction register are read/write. port d has seven bi-directional i/o pins with internal pull-up resistors, pd6..pd0. the port d output buffers can sink 20 ma. as inputs, port d pins that are externally pulled low will source current if the pull-up resistors are activated. some port d pins have alternate functions as shown in table 19: when the pins are used for the alternate function, the ddrd and portd registers have to be set according to the alternate function description. table 19. port d pin alternate functions port pin alternate function pd0 rxd (receive data input for the uart) pd1 txd (transmit data output for the uart) pd2 int0 (external interrupt 0 input) pd3 int1 (external interrupt 1 input) pd4 to (timer/counter0 external input) pd5 t1 (timer/counter1 external input) pd6 icp (timer/counter1input capture pin)
56 at90s2313 0839i ? avr ? 06/02 port d data register ? portd port d data direction register ? ddrd port d input pins address ? pind the port d input pins address (pind) is not a register; this address enables access to the physical value on each port d pin. when reading portd, the port d data latch is read, and when reading pind, the logical values present on the pins are read. port d as general digital i/o pdn, general i/o pin: the dddn bit in the ddrd register selects the direction of this pin. if dddn is set (one), pdn is configured as an output pin. if dddn is cleared (zero), pdn is configured as an input pin. if portdn is set (one) when configured as an input pin, the mos pull-up resistor is activated. to switch the pull-up resistor off, the portdn has to be cleared (zero) or the pin has to be configured as an output pin. the port d pins are tri-stated when a reset condition becomes active, even if the clock is not active. note: 1. n: 6 ? 0, pin number. alternate functions of port d the alternate functions of port d are:  icp ? port d, bit 6 timer/counter1 input capture pin. see the timer/counter1 description for further details.  t1 ? port d, bit 5 t1, timer 1 clock source. see the timer description for further details.  t0 ? port d, bit 4 t0, timer/counter0 clock source. see the timer description for further details. bit 76543210 $12 ($32) ? portd6 portd5 portd4 portd3 portd2 portd1 portd0 portd read/write r r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $11 ($31) ? ddd6 ddd5 ddd4 ddd3 ddd2 ddd1 ddd0 ddrd read/write r r/w r/w r/w r/w r/w r/w r/w initialvalue00000000 bit 76543210 $10 ($30) ? pind6 pind5 pind4 pind3 pind2 pind1 pind0 pind read/write r r r rrrrr initial value 0 n/a n/a n/a n/a n/a n/a n/a table 20. dddn bits on port d pins (1) dddn portdn i/o pull-up comment 0 0 input no tri-state (high-z) 0 1 input yes pdn will source current if ext. pulled low 1 0 output no push-pull zero output 1 1 output no push-pull one output
57 at90s2313 0839i ? avr ? 06/02  int1 ? port d, bit 3 int1, external interrupt source 1. the pd3 pin can serve as an external interrupt source to the mcu. see the interrupt description for further details and how to enable the source.  int0 ? port d, bit 2 int0, external interrupt source 0. the pd2 pin can serve as an external interrupt source to the mcu. see the interrupt description for further details and how to enable the source.  txd ? port d, bit 1 transmit data (data output pin for the uart). when the uart transmitter is enabled, this pin is configured as an output regardless of the value of ddrd1.  rxd ? port d, bit 0 receive data (data input pin for the uart). when the uart receiver is enabled, this pin is configured as an input regardless of the value of ddrd0. when the uart forces thispintobeaninput,alogical ? 1 ? in portd0 will turn on the internal pull-up. port d schematics note that all port pins are synchronized. the synchronization latches are, however, not shown in the figures. figure 44. port d schematic diagram (pin pd0) da ta bus d d q q reset reset c c wd wp rd mos pull- up pd0 rxd rxen wp: wd: rl: rp: rd: rxd: rxen: write portd write ddrd read portd latch read portd pin read ddrd uart receive data uart receive enable ddd0 portd0 rl rp
58 at90s2313 0839i ? avr ? 06/02 figure 45. port d schematic diagram (pin pd1) figure 46. port d schematic diagram (pins pd2 and pd3) da ta bus d d q q reset reset c c wd wp rd rp rl mos pull- up pd1 r r wp: wd: rl: rp: rd: txd: txen: write portd write ddrd read portd latch read portd pin read ddrd uart transmit data uart transmit enable ddd1 portd1 txen txd
59 at90s2313 0839i ? avr ? 06/02 figure 47. port d schematic diagram (pins pd4 and pd5) figure 48. port d schematic diagram (pin pd6) da ta bus d d q q reset reset c c wd wp rd mos pull- up pdn r r wp: wd: rl: rp: rd: n: m: write portd write ddrd read portd latch read portd pin read ddrd 4, 5 0, 1 dddn portdn sense control timerm clock source mux csm2 csm0 rl rp csm1
60 at90s2313 0839i ? avr ? 06/02 memory programming program and data memory lock bits the at90s2313 mcu provides two lock bits that can be left unprogrammed ( ? 1 ? )orcan be programmed ( ? 0 ? ) to obtain the additional features listed in table 21 . the lock bits can only be erased with the chip erase operation. note: 1. in the parallel mode, further programming of the fuse bits are also disabled. program the fuse bits before programming the lock bits. fuse bits the at90s2313 has two fuse bits: spien and fstrt.  when the spien fuse is programmed ( ? 0 ? ), serial program and data downloading is enabled. the default value is programmed ( ? 0 ? ).  when the fstrt fuse is programmed ( ? 0 ? ), the short start-up time is selected. the default value is unprogrammed ( ? 1 ? ). parts with this bit pre-programmed ( ? 0 ? )canbe delivered on demand. the fuse bits are not accessible in serial programming mode. the status of the fuses are not affected by chip erase. signature bytes all atmel microcontrollers have a 3-byte signature code that identifies the device. this code can be read in both serial and parallel mode. the three bytes reside in a separate address space. for the at90s2313 (1) they are: 1. $000: $1e (indicates manufactured by atmel). 2. $001: $91 (indicates 2 kb flash memory). 3. $002: $01 (indicates at90s2313 device when signature byte $001 is $91). note: 1. when both lock bits are programmed (lock mode 3), the signature bytes cannot be read in serial mode. reading the signature bytes will return: $00, $01 and $02. programming the flash and eeprom atmel ? s at90s2313 offers 2k bytes of in-system reprogrammable flash program memory and 128 bytes of eeprom data memory. the at90s2313 is shipped with the on-chip flash program and eeprom data mem- ory arrays in the erased state (i.e., contents = $ff) and ready to be programmed. this device supports a high-voltage (12v) parallel programming mode and a low-voltage serial programming mode. the +12v is used for programming enable only, and no cur- rent of significance is drawn by this pin. the serial programming mode provides a convenient way to download program and data into the at90s2313 inside the user ? s system. the program and eeprom memory arrays in the at90s2313 are programmed byte- by-byte in either programming mode. for the eeprom, an auto-erase cycle is provided table 21. lock bit protection modes memory lock bits protection type mode lb1 lb2 1 1 1 no memory lock features enabled. 2 0 1 further programming of the flash and eeprom is disabled. (1) 3 0 0 same as mode 2, and verify is also disabled.
61 at90s2313 0839i ? avr ? 06/02 within the self-timed write instruction in the serial programming mode. during program- ming, the supply voltage must be in accordance with table 22. parallel programming this section describes how to parallel program and verify flash program memory, eeprom data memory, lock bits and fuse bits in the at90s 2313. signal names in this section, some pins of the at90s2313 are referenced by signal names describing their function during parallel programming. pins not described in the following table are referenced by pin names. see figure 49 and table 23. pins not described in table 23 are referenced by pin names. the xa1/xa0 pins determine the action executed when the xtal1 pin is given a posi- tive pulse. the bit coding is shown in table 24. when pulsing wr or oe , the command loaded determines the action executed. the command is a byte where the different bits are assigned functions as shown in table 25. figure 49. parallel programming . table 22. supply voltage during programming part serial programming parallel programming at90s2313 2.7 - 6.0v 4.5 - 5.5v table 23. pin name mapping signal name in programming mode pin name i/o function rdy/bsy pd1 o 0: device is busy programming, 1: device is ready for new command oe pd2 i output enable (active low) wr pd3 i write pulse (active low) bs pd4 i byte select ( ? 0 ? selects low byte, ? 1 ? selects high byte)
62 at90s2313 0839i ? avr ? 06/02 enter programming mode the following algorithm puts the device in parallel programming mode: 1. apply supply voltage according to table 22, between v cc and gnd. 2. set the reset and bs pin to ? 0 ? and wait at least 100 ns. 3. apply 11.5 - 12.5v to reset . any activity on bs within 100 ns after +12v has been applied to reset , will cause the device to fail entering programming mode. chip erase the chip erase command will erase the flash and eeprom memories, and the lock bits. the lock bits are not reset until the flash and eeprom have been completely erased. the fuse bits are not changed. chip erase must be performed before the flash or eeprom is reprogrammed. load command ? chip erase ? 1. setxa1,xa0to ? 10 ? . this enables command loading. 2. set bs to ? 0 ? . 3. set data to ? 1000 0000 ? . this is the command for chip erase. 4. give xtal1 a positive pulse. this loads the command. xa0 pd5 i xtal action bit 0 xa1 pd6 i xtal action bit 1 data pb7 - 0 i/o bi-directional data bus (output when oe is low) table 24. xa1 and xa0 coding xa1 xa0 action when xtal1 is pulsed 0 0 load flash or eeprom address (high or low address byte determined by bs) 0 1 load data (high or low data byte for flash determined by bs) 1 0 load command 1 1 no action, idle table 25. command byte bit coding command byte command executed 1000 0000 chip erase 0100 0000 write fuse bits 0010 0000 write lock bits 0001 0000 write flash 0001 0001 write eeprom 0000 1000 read signature bytes 0000 0100 read fuse and lock bits 0000 0010 read flash 0000 0011 read eeprom table 23. pin name mapping signal name in programming mode pin name i/o function
63 at90s2313 0839i ? avr ? 06/02 5. give wr a t wlwh_ce wide negative pulse to execute chip erase. see table 26 for t wlwh_ce value. chip erase does not generate any activity on the rdy/bsy pin. programming the flash a: load command ? write flash ? 1. setxa1,xa0to ? 10 ? . this enables command loading. 2. set bs to ? 0 ? . 3. set data to ? 0001 0000 ? . this is the command for write flash. 4. give xtal1 a positive pulse. this loads the command. b: load address high byte 1. setxa1,xa0to ? 00 ? . this enables address loading. 2. set bs to ? 1 ? . this selects high byte. 3. set data = address high byte ($00 - $03). 4. give xtal1 a positive pulse. this loads the address high byte. c: load address low byte 1. setxa1,xa0to ? 00 ? . this enables address loading. 2. set bs to ? 0 ? . this selects low byte. 3. set data = address low byte ($00 - $ff). 4. give xtal1 a positive pulse. this loads the address low byte. d: load data low byte 1. setxa1,xa0to ? 01 ? . this enables data loading. 2. set data = data low byte ($00 - $ff). 3. give xtal1 a positive pulse. this loads the data low byte. e: write data low byte 1. set bs to ? 0 ? . this selects low data. 2. give wr a negative pulse. this starts programming of the data byte. rdy/bsy goes low. 3. wait until rdy/bsy goes high to program the next byte. (see figure 50 for signal waveforms.) f: load data high byte 1. setxa1,xa0to ? 01 ? . this enables data loading. 2. set data = data high byte ($00 - $ff). 3. give xtal1 a positive pulse. this loads the data high byte. g:writedatahighbyte 1. set bs to ? 1 ? . this selects high data. 2. give wr a negative pulse. this starts programming of the data byte. rdy/bsy goes low. 3. wait until rdy/bsy goes high to program the next byte. (see figure 51 for signal waveforms.)
64 at90s2313 0839i ? avr ? 06/02 the loaded command and address are retained in the device during programming. for efficient programming, the following should be considered:  the command needs only be loaded once when writing or reading multiple memory locations.  address high byte needs only be loaded before programming a new 256-word page in the flash.  skip writing the data value $ff; that is, the contents of the entire flash and eeprom after a chip erase. these considerations also apply to eeprom programming and flash, eeprom and signature byte reading. figure 50. programming the flash figure 51. programming the flash (continued) $10 addr. high addr. low data low data xa1 xa0 bs xtal1 wr rdy/bsy reset oe 12v data high data xa1 xa0 bs xtal1 wr rdy/bsy reset +12v oe
65 at90s2313 0839i ? avr ? 06/02 reading the flash the algorithm for reading the flash memory is as follows (refer to ? programming the flash ? for details on command and address loading): 1. a: load command ? 0000 0010 ? . 2. b: load address high byte ($00 - $03). 3. c: load address low byte ($00 - $ff). 4. set oe to ? 0 ? , and bs to ? 0 ? . the flash word low byte can now be read at data. 5. set bs to ? 1 ? . the flash word high byte can now be read from data. 6. set oe to ? 1 ? . programming the eeprom the programming algorithm for the eeprom data memory is as follows (refer to ? pro- gramming the flash ? for details on command, address and data loading): 1. a: load command ? 0001 0001 ? . 2. c: load address low byte ($00 - $7f). 3. d: load data low byte ($00 - $ff). 4. e: write data low byte. reading the eeprom the algorithm for reading the eeprom memory is as follows (refer to ? programming the flash ? for details on command and address loading): 1. a: load command ? 0000 0011 ? . 2. c: load address low byte ($00 - $7f). 3. set oe to ? 0 ? , and bs to ? 0 ? . the eeprom data byte can now be read at data. 4. set oe to ? 1 ? . programming the fuse bits the algorithm for programming the fuse bits is as follows (refer to ? programming the flash ? for details on command and data loading): 1. a: load command ? 0100 0000 ? . 2. d: load data low byte. bit n = ? 0 ? programs and bit n = ? 1 ? erases the fuse bit. bit 5 = spien fuse bit. bit 0 = fstrt fuse bit. bit7-6,4-1= ? 1 ? . these bits are reserved and should be left unprogrammed ( ? 1 ? ). 3. give wr a t wlwh_pfb wide negative pulse to execute the programming; t wlwh_pfb is found in table 26. programming the fuse bits does not generate any activity on the rdy/bsy pin. programming the lock bits the algorithm for programming the lock bits is as follows (refer to ? programming the flash ? on page 63 for details on command and data loading): 1. a: load command ? 0010 0000 ? . 2. d: load data low byte. bit n = ? 0 ? programs the lock bit. bit 2 = lock bit2 bit 1 = lock bit1 bit7-3,0= ? 1 ? . these bits are reserved and should be left unprogrammed ( ? 1 ? ). 3. e: write data low byte. the lock bits can only be cleared by executing chip erase.
66 at90s2313 0839i ? avr ? 06/02 reading the fuse and lock bits the algorithm for reading the fuse and lock bits is as follows (refer to ? programming the flash ? on page 63 for details on command loading): 1. a: load command ? 0000 0100 ? . 2. set oe to ? 0 ? , and bs to ? 1 ? . the status of the fuse and lock bits can now be read at data ( ? 0 ? means programmed). bit 7 = lock bit1 bit 6 = lock bit2 bit 5 = spien fuse bit bit 0 = fstrt fuse bit 3. set oe to ? 1 ? . observe that bs needs to be set to ? 1 ? . reading the signature bytes the algorithm for reading the signature bytes is as follows (refer to ? programming the flash ? on page 63 for details on command and address loading): 1. a: load command ? 0000 1000 ? . 2. c: load address low byte ($00 - $02). set oe to ? 0 ? ,andbsto ? 0 ? . the selected signature byte can now be read at data. 3. set oe to ? 1 ? .
67 at90s2313 0839i ? avr ? 06/02 parallel programming characteristics figure 52. parallel programming timing notes: 1. use t wlwh_ce forchiperaseandt wlwh_pfb for programming the fuse bits. 2. if t wlwh is held longer than t wlrh , no rdy/bsy pulse will be seen. table 26. parallel programming characteristics, t a =25 c 10%, v cc = 5v 10% symbol parameter min typ max units v pp programming enable voltage 11.5 12.5 v i pp programming enable current 250.0 a t dvxh data and control setup before xtal1 high 67.0 ns t xhxl xtal1 pulse width high 67.0 ns t xldx data and control hold after xtal1 low 67.0 ns t xlwl xtal1 low to wr low 67.0 ns t bvwl bsvalidtowr low 67.0 ns t rhbx bs hold after rdy/bsy high 67.0 ns t wlwh wr pulse width low (1) 67.0 ns t whrl wr high to rdy/bsy low (2) 20.0 ns t wlrh wr low to rdy/bsy high (2) 0.5 0.7 0.9 ms t xlol xtal1 low to oe low 67.0 ns t oldv oe low to data valid 20.0 ns t ohdz oe high to data tri-stated 20.0 ns t wlwh_ce wr pulse width low for chip erase 5.0 10.0 15.0 ms t wlwh_pfb wr pulse width low for programming the fuse bits 1.0 1.5 1.8 ms data & contol (data, xa0/1, bs) data write read xtal1 t xhxl t wlwh t dvxh t xlol t oldv t whrl t wlrh wr rdy/bsy oe t xldx t xlwl t rhbx t ohdz t bvwl
68 at90s2313 0839i ? avr ? 06/02 serial downloading both the program and data memory arrays can be programmed using the serial spi bus while reset is pulled to gnd. the serial interface consists of pins sck, mosi (input) and miso (output). see figure 53. after reset is set low, the programming enable instruction needs to be executed first before program/erase instructions can be executed. figure 53. serial programming and verify for the eeprom, an auto-erase cycle is provided within the self-timed write instruction and there is no need to first execute the chip erase instruction. the chip erase instruc- tion turns the content of every memory location in both the program and eeprom arrays into $ff. the program and eeprom memory arrays have separate address spaces: $0000 to $03ff for program flash memory and $000 to $07f for eeprom data memory. either an external clock is supplied at pin xtal1 or a crystal needs to be connected across pins xtal1 and xtal2. the minimum low and high periods for the serial clock (sck) input are defined as follows: low: > 2 xtal1 clock cycle high: > 2 xtal1 clock cycles serial programming algorithm when writing serial data to the at90s2313, data is clocked on the rising edge of sck. when reading data from the at90s2313, data is clocked on the falling edge of sck. see figure 54, figure and table 29 for timing details. to program and verify the at90s2313 in the serial programming mode, the following sequence is recommended (see 4-byte instruction formats in table 28 ): 1. power-up sequence: apply power between v cc and gnd while reset and sck are set to ? 0 ? .ifacrys- tal is not connected across pins xtal1 and xtal2, apply a clock signal to the xtal1 pin. in some systems, the programmer cannot guarantee that sck is held low during power-up. in this case, reset must be given a positive pulse of at least two xtal1 cycles duration after sck has been set to ? 0 ? . 2. wait for at least 20 ms and enable serial programming by sending the program- ming enable serial instruction to the mosi (pb5) pin. 3. the serial programming instructions will not work if the communication is out of synchronization. when in sync, the second byte ($53) will echo back when issu- at90s2313 vcc 2.7 - 6.0v pb7 pb6 pb5 reset gnd xtal1 sck miso mosi clock input
69 at90s2313 0839i ? avr ? 06/02 ing the third byte of the programming enable instruction. whether the echo is correct or not, all four bytes of the instruction must be transmitted. if the $53 did not echo back, give sck a positive pulse and issue a new programming enable instruction. if the $53 is not seen within 32 attempts, there is no functional device connected. 4. if a chip erase is performed (must be done to erase the flash), wait t wd_erase after the instruction, give reset a positive pulse, and start over from step 2. see table 30 for t wd_erase value. 5. the flash or eeprom array is programmed one byte at a time by supplying the address and data together with the appropriate write instruction. an eeprom memory location is first automatically erased before new data is written. use data polling to detect when the next byte in the flash or eeprom can be writ- ten. if polling is not used, wait t wd_prog before transmitting the next instruction. see table 31 for t wd_prog value. in an erased device, no $ffs in the data file(s) need to be programmed. 6. any memory location can be verified by using the read instruction that returns the content at the selected address at the serial output miso (pb6) pin. 7. at the end of the programming session, reset can be set high to commence normal operation. 8. power-off sequence (if needed): set xtal1 to ? 0 ? (if a crystal is not used). set reset to ? 1 ? . turn v cc power off. data polling eeprom when a byte is being programmed into the eeprom, reading the address location being programmed will give the value p1 until the auto-erase is finished, and then the value p2. see table 27 for p1 and p2 values. at the time the device is ready for a new eeprom byte, the programmed value will read correctly. this is used to determine when the next byte can be written. this will not work for the values p1 and p2, so when programming these values, the user will have to wait for at least the prescribed time t wd_prog before programming the next byte. see table 30 for t wd_prog value. as a chip-erased device contains $ff in all locations, program- ming of addresses that are meant to contain $ff can be skipped. this does not apply if the eeprom is reprogrammed without first chip-erasing the device. table 27. read back value during eeprom polling part p1 p2 at90s2313 $80 $7f
70 at90s2313 0839i ? avr ? 06/02 data polling flash when a byte is being programmed into the flash, reading the address location being programmed will give the value $7f. at the time the device is ready for a new byte, the programmed value will read correctly. this is used to determine when the next byte can be written. this will not work for the value $7f, so when programming this value, the user will have to wait for at least t wd_prog before programming the next byte. as a chip- erased device contains $ff in all locations, programming of addresses that are meant to contain $ff can be skipped. figure 54. serial programming waveforms note: a = address high bits, b = address low bits, h =0 ? low byte, 1 ? high byte, o = data out, i = data in, x = don ? t care, 1 = lock bit 1, 2 = lock bit 2. note: 1. the signature bytes are not readable in lock mode 3, i.e. both lock bits programmed. table 2 8. serial programming instruction set instruction instruction format operation byte 1 byte 2 byte 3 byte4 programming enable 1010 1100 0101 0011 xxxx xxxx xxxx xxxx enable serial programming while reset is low. chip erase 1010 1100 100x xxxx xxxx xxxx xxxx xxxx chip erase flash and eeprom memory arrays. read program memory 0010 h 000 xxxx xx aa bbbb bbbb oooo oooo read h (highorlow)data o from program memory at word address a : b . write program memory 0100 h 000 xxxx xx aa bbbb bbbb iiii iiii write h (high or low) data i to program memory at word address a : b . read eeprom memory 1010 0000 xxxx xxxx x bbb bbbb oooo oooo read data o from eeprom memory at address b . write eeprom memory 1100 0000 xxxx xxxx x bbb bbbb iiii iiii write data i to eeprom memory at address b . write lock bits 1010 1100 111x x 21 x xxxx xxxx xxxx xxxx write lock bits. set bits 1,2 = ? 0 ? to program lock bits. read signature bytes 0011 0000 xxxx xxxx xxxx xx bb oooo oooo read signature byte o at address b . (1)
71 at90s2313 0839i ? avr ? 06/02 serial programming characteristics figure 55. serial programming timing table 29. serial programming characteristics, t a =-40 cto85 c, v cc =2.7-6.0v (unless otherwise noted) symbol parameter min typ max units 1/t clcl oscillator frequency (v cc = 2.7 - 6.0v) 0 4.0 mhz t clcl oscillator period (v cc = 2.7 - 6.0v) 250.0 ns 1/t clcl oscillator frequency (v cc =4.0-6.0v) 0 10.0 mhz t clcl oscillator period (v cc = 4.0 - 6.0v) 100.0 ns t shsl sck pulse width high 2.0 t clcl ns t slsh sck pulse width low 2.0 t clcl ns t ovsh mosi setup to sck high t clcl ns t shox mosi hold after sck high 2.0 t clcl ns t sliv sck low to miso valid 10.0 16.0 32.0 ns table 30. minimum wait delay after the chip erase instruction symbol 3.2v 3.6v 4.0v 5.0v t wd_erase 18 ms 14 ms 12 ms 8 ms table 31. minimum wait delay after writing a flash or eeprom location symbol 3.2v 3.6v 4.0v 5.0v t wd_prog 9ms 7ms 6ms 4ms mosi miso sck t ovsh t shsl t slsh t shox t sliv
72 at90s2313 0839i ? avr ? 06/02 electrical characteristics absolute maximum ratings* operating temperature .................................. -55 cto+125 c *notice: stresses beyond those listed under ? absolute maximum ratings ? may cause permanent dam- age to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. storage temperature ..................................... -65 cto+150 c voltage on any pin except reset with respect to ground ...............................-1.0v to v cc +0.5v voltage on reset with respect to ground ....-1.0v to +13.0v maximum operating voltage ............................................ 6.6v dc current per i/o pin ............................................... 40.0 ma dc current v cc and gnd pins ................................ 200.0 ma dc characteristics t a =-40 cto85 c, v cc = 2.7v to 6.0v (unless otherwise noted) symbol parameter condition min typ max units v il input low voltage (except xtal1) -0.5 0.3 v cc (1) v v il1 input low voltage (xtal1) -0.5 0.3 v cc (1) v v ih input high voltage (except xtal1, reset )0.6v cc (2) v cc +0.5 v v ih1 input high voltage (xtal1) 0.7 v cc (2) v cc +0.5 v v ih2 input high voltage (reset )0.85v cc (2) v cc +0.5 v v ol output low voltage (3) (ports b, d) i ol =20ma,v cc =5v i ol =10ma,v cc =3v 0.6 0.5 v v v oh output high voltage (4) (ports b, d) i oh =-3ma,v cc =5v i oh =-1.5ma,v cc =3v 4.3 2.3 v v i il input leakage current i/o pin v cc = 6v, pin low (absolute value) 1.5 a i ih input leakage current i/o pin v cc =6v,pinhigh (absolute value) 980.0 na rrst reset pull-up resistor 100.0 500.0 k ? r i/o i/o pin pull-up resistor 35.0 120.0 k ? i cc power supply current active mode, v cc =3v,4mhz 3.0 ma idle mode v cc =3v,4mhz 1.0 ma i cc power-down mode (5) wdt enabled, v cc = 3v 9.0 15.0 a wdt disabled, v cc = 3v <1.0 2.0 a v acio analog comparator input offset voltage v cc =5v v in =v cc /2 40.0 mv i aclk analog comparator input leakage current v cc =5v v in =v cc /2 -50.0 50.0 na t acpd analog comparator propagation delay v cc =2.7v v cc =4.0v 750.0 500.0 ns
73 at90s2313 0839i ? avr ? 06/02 notes: 1. ? max ? means the highest value where the pin is guaranteed to be read as low. 2. ? min ? means the lowest value where the pin is guaranteed to be read as high. 3. although each i/o port can sink more than the test conditions (20 ma at v cc =5v, 10 ma at v cc = 3v) under steady state conditions (non-transient), the following must be observed: 1] the sum of all i ol , for all ports, should not exceed 200 ma 2] the sum of all ii ol , for port d0 - d5 and xtal2 should not exceed 100 ma. 3] the sum of all i ol , for ports b0 - b7 and d6 should not exceed 100 ma. if i ol exceeds the test condition, v ol may exceed the related specification. pins are not guaranteed to sink current greater than the listed test condition. 4. although each i/o port can source more than the test conditions (3 ma at v cc =5v, 1.5 ma at v cc = 3v) under steady state conditions (non-transient), the following must be observed: 1] the sum of all i oh , for all ports, should not exceed 200 ma 2] the sum of all i oh , for port d0 - d5 and xtal2 should not exceed 100 ma. 3] the sum of all i oh , for ports b0 - b7 and d6 should not exceed 100 ma. if i oh exceeds the test condition, v oh may exceed the related specification. pins are not guaranteed to source current greater than the listed test condition. 5. minimum v cc for power-down is 2v. external clock drive waveforms figure 56. external clock external clock drive symbol parameter v cc =2.7vto6.0v v cc =4.0vto6.0v units minmaxminmax 1/t clcl oscillator frequency 0 4 0 10.0 mhz t clcl clock period 250.0 100.0 ns t chcx high time 100.0 40.0 ns t clcx low time 100.0 40.0 ns t clch rise time 1.6 0.5 s t chcl fall time 1.6 0.5 s vil1 vih1
74 at90s2313 0839i ? avr ? 06/02 typical characteristics the following charts show typical behavior. these figures are not tested during manu- facturing. all current consumption measurements are performed with all i/o pins configured as inputs and with internal pull-ups enabled. a sine wave generator with rail- to-rail output is used as clock source. the power consumption in power-down mode is independent of clock selection. the current consumption is a function of several factors such as: operating voltage, operating frequency, loading of i/o pins, switching rate of i/o pins, code executed and ambient temperature. the dominating factors are operating voltage and frequency. the current drawn from capacitive loaded pins may be estimated (for one pin) as c l  v cc  fwherec l = load capacitance, v cc = operating voltage and f = average switching frequency of i/o pin. the parts are characterized at frequencies higher than test limits. parts are not guaran- teed to function properly at frequencies higher than the ordering code indicates. the difference between current consumption in power-down mode with watchdog timer enabled and power-down mode with watchdog timer disabled represents the dif- ferential current drawn by the watchdog timer. figure 57. active supply current vs. frequency 0 5 10 15 20 25 0 1 2 3 4 5 6 7 8 910 11 12 13 14 15 active supply current vs. frequency t = 25?c a frequency (mhz) i cc (ma) v cc = 5.5v v cc = 5v v cc = 2.7v v cc = 3.0v v cc = 3.3v v cc = 3.6v v cc = 4v v cc = 4.5v v cc = 6v
75 at90s2313 0839i ? avr ? 06/02 figure 58. active supply current vs. v cc figure 59. idle supply current vs. frequency 0 2 4 6 8 10 12 2 2.5 3 3.5 4 4.5 5 5.5 6 active supply current vs. v cc frequency = 4 mhz i cc (ma) v cc (v) t = 85 ? c a t = 25 ? c a 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 v cc = 6v v cc = 5.5v v cc = 5v v cc = 4.5v v cc = 4v v cc = 3.6v v cc = 3.3v v cc = 3.0v v cc = 2.7v idle supply current vs. frequency t = 25 ? c a frequency (mhz) i cc (ma)
76 at90s2313 0839i ? avr ? 06/02 figure 60. idle supply current vs. v cc figure 61. power-down supply current vs. v cc idle supply current vs. v cc i cc (ma) v cc (v) frequency = 4 mhz 0 0.5 1 1.5 2 2.5 3 3.5 2 2.5 3 3.5 4 4.5 5 5.5 6 t = 25 ? c a t = 85 ? c a 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2 2.5 3 3.5 4 4.5 5 5.5 6 t = 85 ? c a t = 25 ? c a power down supply current vs. v cc i cc (?) v cc (v) watchdog timer disabled t = 45 ? c a t = 70 ? c a
77 at90s2313 0839i ? avr ? 06/02 figure 62. power-down supply current vs. v cc figure 63. analog comparator current vs. v cc 0 20 40 60 80 100 120 140 160 2 2.5 3 3.5 4 4.5 5 5.5 6 t = 85 ? c a t = 25 ? c a power down supply current vs. v cc i cc (?) v cc (v) watchdog timer enabled 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 2 2.5 3 3.5 4 4.5 5 5.5 6 analog comparator current vs. v cc i cc (ma) v cc (v) t = 25 ? c a t = 85 ? c a
78 at90s2313 0839i ? avr ? 06/02 note: analog comparator offset voltage is measured as absolute offset. figure 64. analog comparator offset voltage vs. common mode voltage figure 65. analog comparator offset voltage vs. common mode voltage 0 2 4 6 8 10 12 14 16 18 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 analog comparator offset voltage vs. v = 5v cc common mode voltage common mode voltage (v) offset voltage (mv) t = 85 ? c a t = 25 ? c a 0 2 4 6 8 10 0 0.5 1 1.5 2 2.5 3 analog comparator offset voltage vs. common mode voltage common mode voltage (v) offset voltage (mv) v = 2.7v cc t = 85 ? c a t = 25 ? c a
79 at90s2313 0839i ? avr ? 06/02 figure 66. analog comparator input leakage current figure 67. watchdog oscillator frequency vs. v cc 60 50 40 30 20 10 0 -10 0 0.5 1.5 122.53.5 3 4 4.5 5 6 6.5 7 5.5 analog comparator input leakage current t = 25 ? c a i (na) aclk v (v) in v = 6v cc 0 200 400 600 800 1000 1200 1400 1600 2 2.5 3 3.5 4 4.5 5 5.5 6 t = 85 ? c a t = 25 ? c a watchdog oscillator frequency vs. v cc v (v) cc f (khz) rc
80 at90s2313 0839i ? avr ? 06/02 note: sink and source capabilities of i/o ports are measured on one pin at a time. figure 68. pull-up resistor current vs. input voltage figure 69. pull-up resistor current vs. input voltage 0 20 40 60 80 100 120 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 pull-up resistor current vs. input voltage v = 5v cc i ( a) op v (v) op t = 85 ? c a t = 25 ? c a 0 5 10 15 20 25 30 0 0.5 1 1.5 2 2.5 3 pull-up resistor current vs. input voltage i ( a) op v (v) op v = 2.7v cc t = 85 ? c a t = 25 ? c a
81 at90s2313 0839i ? avr ? 06/02 figure 70. i/o pin sink current vs. output voltage figure 71. i/o pin source current vs. output voltage 0 10 20 30 40 50 60 70 0 0.5 1 1.5 2 2.5 3 v = 5v cc i (ma) ol v (v) ol t = 85 ? c a t = 25 ? c a i/o pin sink current vs. output voltage 0 2 4 6 8 10 12 14 16 18 20 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 i/o pin source current vs. output voltage v = 5v cc i (ma) oh v (v) oh t = 85 ? c a t = 25 ? c a
82 at90s2313 0839i ? avr ? 06/02 figure 72. i/o pin sink current vs. output voltage figure 73. i/o pin source current vs. output voltage 0 5 10 15 20 25 0 0.5 1 1.5 2 i (ma) ol v (v) ol t = 85 ? c a t = 25 ? c a i/o pin sink current vs. output voltage v = 2.7v cc 0 1 2 3 4 5 6 0 0.5 1 1.5 2 2.5 3 i/o pin source current vs. output voltage i (ma) oh v (v) oh t = 85 ? c a t = 25 ? c a v = 2.7v cc
83 at90s2313 0839i ? avr ? 06/02 figure 74. i/o pin input threshold voltage vs. v cc figure 75. i/o pin input hysteresis vs. v cc 0 0.5 1 1.5 2 2.5 2.7 4.0 5.0 threshold voltage (v) v cc i/o pin input threshold voltage vs. v cc t = 25 ? c a 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 2.7 4.0 5.0 input hysteresis (v) v cc i/o pin input hysteresis vs. v cc t = 25 ? c a
84 at90s2313 0839i ? avr ? 06/02 notes: 1. for compatibility with future devices, reserved bits should be written to zero if accessed. reserved i/o memory addresses should never be written. 2. some of the status flags are cleared by writing a logical ? 1 ? to them. note that the cbi and sbi instructions will operate on all bits in the i/o register, writing a ? 1 ? back into any flag read as set, thus clearing the flag. the cbi and sbi instructions work with registers $00 to $1f only. register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page $3f ($5f) sreg i t h s v n z c page 16 $3e ($5e) reserved $3d ($5d) spl sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 page 17 $3c ($5c) reserved $3b ($5b) gimsk int1 int0 ? ? ? ? ? ? page 22 $3a ($5a) gifr intf1 intf0 page 23 $39 ($59) timsk toie1 ocie1a ? ? ticie1 ? toie0 ? page 23 $38 ($58) tifr tov1 ocf1a ? ? icf1 ? tov0 ? page 24 $37 ($57) reserved $36 ($56) reserved $35 ($55) mcucr ? ? se sm isc11 isc10 isc01 isc00 page 25 $34 ($54) reserved $33 ($53) tccr0 ? ? ? ? ? cs02 cs01 cs00 page 29 $32 ($52) tcnt0 timer/counter0 (8 bits) page 29 $31 ($51) reserved $30 ($50) reserved $2f ($4f) tccr1a com1a1 com1a0 ? ? ? ? pwm11 pwm10 page 31 $2e ($4e) tccr1b icnc1 ices1 . ? ctc1 cs12 cs11 cs10 page 32 $2d ($4d) tcnt1h timer/counter1 ? counter register high byte page 33 $2c ($4c) tcnt1l timer/counter1 ? counter register low byte page 33 $2b ($4b) ocr1ah timer/counter1 ? compare register high byte page 34 $2a ($4a) ocr1al timer/counter1 ? compare register low byte page 34 $29 ($49) reserved $28 ($48) reserved $27 ($47) reserved $26 ($46) reserved $25 ($45) icr1h timer/counter1 ? input capture register high byte page 34 $24 ($44) icr1l timer/counter1 ? input capture register low byte page 34 $23 ($43) reserved $22 ($42) reserved $21 ($41) wdtcr ? ? ? wdtoe wde wdp2 wdp1 wdp0 page 37 $20 ($40) reserved $1f ($3f) reserved $1e ($3e) eear ? eeprom address register page 39 $1d ($3d) eedr eeprom data register page 39 $1c ($3c) eecr ? ? ? ? ? eemwe eewe eere page 40 $1b ($3b) reserved $1a ($3a) reserved $19 ($39) reserved $18 ($38) portb portb7 portb6 portb5 portb4 portb3 portb2 portb1 portb0 page 50 $17 ($37) ddrb ddb7 ddb6 ddb5 ddb4 ddb3 ddb2 ddb1 ddb0 page 50 $16 ($36) pinb pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 page 50 $15 ($35) reserved $14 ($34) reserved $13 ($33) reserved $12 ($32) portd ? portd6 portd5 portd4 portd3 portd2 portd1 portd0 page 56 $11 ($31) ddrd ? ddd6 ddd5 ddd4 ddd3 ddd2 ddd1 ddd0 page 56 $10 ($30) pind ? pind6 pind5 pind4 pind3 pind2 pind1 pind0 page 56 ... reserved $0c ($2c) udr uart i/o data register page 45 $0b ($2b) usr rxc txc udre fe or ? ? ? page 45 $0a ($2a) ucr rxcie txcie udrie rxen txen chr9 rxb8 txb8 page 46 $09 ($29) ubrr uart baud rate register page 48 $08 ($28) acsr acd ? aco aci acie acic acis1 acis0 page 48 ? reserved $00 ($20) reserved
85 at90s2313 0839i ? avr ? 06/02 instruction set summary mnemonic operands description operation flags # clocks arithmetic and logic instructions add rd, rr add two registers rd rd + rr z,c,n,v,h 1 adc rd, rr add with carry two registers rd rd + rr + c z,c,n,v,h 1 adiw rdl, k add immediate to word rdh:rdl rdh:rdl + k z,c,n,v,s 2 sub rd, rr subtract two registers rd rd ? rr z,c,n,v,h 1 subi rd, k subtract constant from register rd rd ? k z,c,n,v,h 1 sbiw rdl, k subtract immediate from word rdh:rdl rdh:rdl ? k z,c,n,v,s 2 sbc rd, rr subtract with carry two registers rd rd ? rr ? c z,c,n,v,h 1 sbci rd, k subtract with carry constant from reg. rd rd ? k ? c z,c,n,v,h 1 and rd, rr logical and registers rd rd ? rr z,n,v 1 andi rd, k logical and register and constant rd rd ? k z,n,v 1 or rd, rr logical or registers rd rd v rr z,n,v 1 ori rd, k logical or register and constant rd rd v k z,n,v 1 eor rd, rr exclusive or registers rd rd rr z,n,v 1 com rd one ? s complement rd $ff ? rd z,c,n,v 1 neg rd two ? s complement rd $00 ? rd z,c,n,v,h 1 sbr rd,k setbit(s)inregister rd rd v k z,n,v 1 cbr rd, k clear bit(s) in register rd rd ? ($ff ? k) z,n,v 1 inc rd increment rd rd + 1 z,n,v 1 dec rd decrement rd rd ? 1 z,n,v 1 tst rd test for zero or minus rd rd ? rd z,n,v 1 clr rd clear register rd rd rd z,n,v 1 ser rd set register rd $ff none 1 branch instructions rjmp k relative jump pc pc+k+1 none 2 ijmp indirect jump to (z) pc z none 2 rcall k relative subroutine call pc pc+k+1 none 3 icall indirect call to (z) pc z none 3 ret subroutine return pc stack none 4 reti interrupt return pc stack i 4 cpse rd, rr compare, skip if equal if (rd = rr) pc pc + 2 or 3 none 1/2 cp rd, rr compare rd ? rr z,n,v,c,h 1 cpc rd, rr compare with carry rd ? rr ? c z,n,v,c,h 1 cpi rd, k compare register with immediate rd ? k z,n,v,c,h 1 sbrc rr, b skip if bit in register cleared if (rr(b) = 0) pc pc + 2 or 3 none 1/2 sbrs rr, b skip if bit in register is set if (rr(b) = 1) pc pc + 2 or 3 none 1/2 sbic p, b skip if bit in i/o register cleared if (p(b) = 0) pc pc + 2 or 3 none 1/2 sbis p, b skip if bit in i/o register is set if (r(b) = 1) pc pc + 2 or 3 none 1/2 brbs s, k branch if status flag set if (sreg(s) = 1) then pc pc + k + 1 none 1/2 brbc s, k branch if status flag cleared if (sreg(s) = 0) then pc pc + k + 1 none 1/2 breq k branch if equal if (z = 1) then pc pc + k + 1 none 1/2 brne k branch if not equal if (z = 0) then pc pc + k + 1 none 1/2 brcs k branch if carry set if (c = 1) then pc pc + k + 1 none 1/2 brcc k branch if carry cleared if (c = 0) then pc pc + k + 1 none 1/2 brsh k branch if same or higher if (c = 0) then pc pc + k + 1 none 1/2 brlo k branch if lower if (c = 1) then pc pc + k + 1 none 1/2 brmi k branch if minus if (n = 1) then pc pc + k + 1 none 1/2 brpl k branch if plus if (n = 0) then pc pc + k + 1 none 1/2 brge k branch if greater or equal, signed if (n v = 0) then pc pc + k + 1 none 1/2 brlt k branch if less than zero, signed if (n v = 1) then pc pc + k + 1 none 1/2 brhs k branch if half-carry flag set if (h = 1) then pc pc + k + 1 none 1/2 brhc k branch if half-carry flag cleared if (h = 0) then pc pc + k + 1 none 1/2 brts k branch if t-flag set if (t = 1) then pc pc + k + 1 none 1/2 brtc k branch if t-flag cleared if (t = 0) then pc pc + k + 1 none 1/2 brvs k branch if overflow flag is set if (v = 1) then pc pc + k + 1 none 1/2 brvc k branch if overflow flag is cleared if (v = 0) then pc pc + k + 1 none 1/2 brie k branch if interrupt enabled if (i = 1) then pc pc + k + 1 none 1/2 brid k branch if interrupt disabled if (i = 0) then pc pc + k + 1 none 1/2
86 at90s2313 0839i ? avr ? 06/02 data transfer instructions mov rd, rr move between registers rd rr none 1 ldi rd, k load immediate rd k none 1 ld rd, x load indirect rd (x) none 2 ld rd, x+ load indirect and post-inc. rd (x), x x + 1 none 2 ld rd, -x load indirect and pre-dec. x x ? 1, rd (x) none 2 ld rd, y load indirect rd (y) none 2 ld rd, y+ load indirect and post-inc. rd (y), y y + 1 none 2 ld rd, -y load indirect and pre-dec. y y ? 1, rd (y) none 2 ldd rd, y+q load indirect with displacement rd (y + q) none 2 ld rd, z load indirect rd (z) none 2 ld rd, z+ load indirect and post-inc. rd (z), z z+1 none 2 ld rd, -z load indirect and pre-dec. z z-1,rd (z) none 2 ldd rd, z+q load indirect with displacement rd (z + q) none 2 lds rd, k load direct from sram rd (k) none 2 st x, rr store indirect (x) rr none 2 st x+, rr store indirect and post-inc. (x) rr, x x + 1 none 2 st -x, rr store indirect and pre-dec. x x-1,(x) rr none 2 st y, rr store indirect (y) rr none 2 st y+, rr store indirect and post-inc. (y) rr, y y + 1 none 2 st -y, rr store indirect and pre-dec. y y-1,(y) rr none 2 std y+q, rr store indirect with displacement (y + q) rr none 2 st z, rr store indirect (z) rr none 2 st z+, rr store indirect and post-inc. (z) rr, z z + 1 none 2 st -z, rr store indirect and pre-dec. z z-1,(z) rr none 2 std z+q, rr store indirect with displacement (z + q) rr none 2 sts k, rr store direct to sram (k) rr none 2 lpm load program memory r0 (z) none 3 in rd, p in port rd p none 1 out p, rr out port p rr none 1 push rr push register on stack stack rr none 2 pop rd pop register from stack rd stack none 2 bit and bit-test instructions sbi p, b set bit in i/o register i/o(p,b) 1 none 2 cbi p, b clear bit in i/o register i/o(p,b) 0 none 2 lsl rd logical shift left rd(n+1) rd(n), rd(0) 0 z,c,n,v 1 lsr rd logical shift right rd(n) rd(n+1), rd(7) 0 z,c,n,v 1 rol rd rotate left through carry rd(0) c, rd(n+1) rd(n), c rd(7) z,c,n,v 1 ror rd rotate right through carry rd(7) c, rd(n) rd(n+1), c rd(0) z,c,n,v 1 asr rd arithmetic shift right rd(n) rd(n+1), n = 0..6 z,c,n,v 1 swap rd swap nibbles rd(3..0) rd(7..4), rd(7..4) rd(3..0) none 1 bset s flag set sreg(s) 1sreg(s)1 bclr s flag clear sreg(s) 0sreg(s)1 bst rr, b bit store from register to t t rr(b) t 1 bld rd, b bit load from t to register rd(b) t none 1 sec set carry c 1c1 clc clear carry c 0c1 sen set negative flag n 1n1 cln clear negative flag n 0n1 sez set zero flag z 1z1 clz clear zero flag z 0z1 sei global interrupt enable i 1i1 cli global interrupt disable i 0i1 ses set signed test flag s 1s1 cls clear signed test flag s 0s1 sev set two ? s complement overflow v 1v1 clv clear two ? s complement overflow v 0v1 set set t in sreg t 1t1 clt clear t in sreg t 0t1 seh sethalf-carryflaginsreg h 1h1 clh clear half-carry flag in sreg h 0h1 nop no operation none 1 sleep sleep (see specific descr. for sleep function) none 1 wdr watchdog reset (see specific descr. for wdr/timer) none 1 instruction set summary (continued) mnemonic operands description operation flags # clocks
87 at90s2313 0839i ? avr ? 06/02 ordering information speed (mhz) power supply ordering code package operation range 4 2.7 - 6.0v at90s2313-4pc at90s2313-4sc 20p3 20s commercial (0 cto70 c) at90s2313-4pi at90s2313-4si 20p3 20s industrial (-40 cto85 c) 10 4.0 - 6.0v at90s2313-10pc at90s2313-10sc 20p3 20s commercial (0 cto70 c) at90s2313-10pi at90s2313-10si 20p3 20s industrial (-40 cto85 c) package type 20p3 20-lead, 0.300" wide, plastic dual inline package (pdip) 20s 20-lead, 0.300" wide, plastic gull wing small outline (soic)
88 at90s2313 0839i ? avr ? 06/02 packaging information 20p3 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 20p3 , 20-lead (0.300"/7.62 mm wide) plastic dual inline package (pdip) b 20p3 09/28/01 pin 1 e1 a1 b e b1 c l seating plane a d e eb ec common dimensions (unit of measure = mm) symbol min nom max note a 5.334 a1 0.381 d 25.984 25.493 note 2 e 7.620 8.255 e1 6.096 7.112 note 2 b 0.356 0.559 b1 1.270 1.551 l 2.921 3.810 c 0.203 0.356 eb 10.922 ec 0.000 1.524 e 2.540 typ notes: 1. this package conforms to jedec reference ms-001, variation ad. 2. dimensions d and e1 do not include mold flash or protrusion. mold flash or protrusion shall not exceed 0.25 mm (0.010").
89 at90s2313 0839i ? avr ? 06/02 20s 7.60 (0.2992) 7.40 (0.2914) 0.51(0.020) 0.33(0.013) 10.65 (0.419) 10.00 (0.394) pin 1 id 1.27 (0.050) bsc 13.00 (0.5118) 12.60 (0.4961) 0.30(0.0118) 0.10 (0.0040) 2.65 (0.1043) 2.35 (0.0926) 0 ~ 8 1.27 (0.050) 0.40 (0.016) 0.32 (0.0125) 0.23 (0.0091) *controlling dimension: inches 20s, 20-lead, plastic gull wing small outline (soic), 0.300" body. dimensions in millineters and (inches)* jedec standard ms-013 pin 1 rev. a 04/11/2001
i at90s2313 0839i ? avr ? 06/02 table of contents features................................................................................................. 1 pin configuration.................................................................................. 1 description ............................................................................................ 2 pin descriptions.................................................................................................... 3 crystal oscillator................................................................................................... 4 architectural overview......................................................................... 5 general purpose register file ............................................................................. 7 alu ? arithmetic logic unit.................................................................................. 8 in-system programmable flash program memory .............................................. 8 eeprom data memory........................................................................................ 8 sram data memory............................................................................................. 9 program and data addressing modes................................................................ 10 memory access and instruction execution timing ............................................. 14 i/o memory ......................................................................................................... 15 reset and interrupt handling.............................................................................. 18 sleep modes....................................................................................................... 27 timer/counters ................................................................................... 27 timer/counter prescaler..................................................................................... 27 8-bit timer/counter0........................................................................................... 28 16-bit timer/counter1......................................................................................... 30 watchdog timer.................................................................................. 37 eeprom read/write access............................................................. 39 prevent eeprom corruption ............................................................................. 41 uart.................................................................................................... 42 data transmission.............................................................................................. 42 data reception ................................................................................................... 43 uart control ..................................................................................................... 45 analog comparator ............................................................................ 48 i/o ports............................................................................................... 50 port b.................................................................................................................. 50 port d.................................................................................................................. 55 memory programming........................................................................ 60 program and data memory lock bits................................................................. 60 fuse bits............................................................................................................. 60 signature bytes .................................................................................................. 60 programming the flash and eeprom............................................................... 60
ii at90s2313 0839i ? avr ? 06/02 parallel programming ......................................................................................... 61 parallel programming characteristics ................................................................ 67 serial downloading............................................................................................. 68 serial programming characteristics ................................................................... 71 electrical characteristics................................................................... 72 absolute maximum ratings*............................................................................... 72 dc characteristics.............................................................................................. 72 external clock drive waveforms ........................................................................ 73 external clock drive ........................................................................................... 73 typical characteristics ...................................................................... 74 register summary .............................................................................. 84 instruction set summary ................................................................... 85 ordering information.......................................................................... 87 packaging information ....................................................................... 88 20p3 ................................................................................................................... 88 20s ..................................................................................................................... 89 table of contents .................................................................................. i
printed on recycled paper. ? atmel corporation 2002. atmel corporation makes no warranty for the use of its products, other than those expressly contained in the company ? s standard warranty whichisdetailedinatmel ? s terms and conditions located on the company ? s web site. the company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. no licenses to patents or other intellectual property of atmel are granted by the company in connection with the sale of atmel products, expressly or by implication. atmel ? s products are not authorized for use as critical components in life support devices or systems. atmel headquarters atmel operations corporate headquarters 2325 orchard parkway san jose, ca 95131 tel 1(408) 441-0311 fax 1(408) 487-2600 europe atmel sarl route des arsenaux 41 case postale 80 ch-1705 fribourg switzerland tel (41) 26-426-5555 fax (41) 26-426-5500 asia room 1219 chinachem golden plaza 77 mody road tsimhatsui east kowloon hong kong tel (852) 2721-9778 fax (852) 2722-1369 japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel (81) 3-3523-3551 fax (81) 3-3523-7581 memory 2325 orchard parkway san jose, ca 95131 tel 1(408) 441-0311 fax 1(408) 436-4314 microcontrollers 2325 orchard parkway san jose, ca 95131 tel 1(408) 441-0311 fax 1(408) 436-4314 la chantrerie bp 70602 44306 nantes cedex 3, france tel (33) 2-40-18-18-18 fax (33) 2-40-18-19-60 asic/assp/smart cards zone industrielle 13106 rousset cedex, france tel (33) 4-42-53-60-00 fax (33) 4-42-53-60-01 1150 east cheyenne mtn. blvd. colorado springs, co 80906 tel 1(719) 576-3300 fax 1(719) 540-1759 scottish enterprise technology park maxwell building east kilbride g75 0qr, scotland tel (44) 1355-803-000 fax (44) 1355-242-743 rf/automotive theresienstrasse 2 postfach 3535 74025 heilbronn, germany tel (49) 71-31-67-0 fax (49) 71-31-67-2340 1150 east cheyenne mtn. blvd. colorado springs, co 80906 tel 1(719) 576-3300 fax 1(719) 540-1759 biometrics/imaging/hi-rel mpu/ high speed converters/rf datacom avenue de rochepleine bp 123 38521 saint-egreve cedex, france tel (33) 4-76-58-30-00 fax (33) 4-76-58-34-80 e-mail literature@atmel.com web site http://www.atmel.com 0839i ? avr ? 06/02 0m at m e l ? and avr ? are the registered trademarks of atmel. other terms and product names may be the trademarks of others.


▲Up To Search▲   

 
Price & Availability of AT90S231302

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X